细胞模板与ng网格中的过滤器(Cell template with filter in ng

编程入门 行业动态 更新时间:2024-10-17 11:26:12
细胞模板与ng网格中的过滤器(Cell template with filter in ng-grid)

我创建了一个依赖于过滤器的单元格模板,但不处理过滤器。

该单元格定义为{field:'status', displayName:'Status', cellTemplate: 'cell/statusCellTemplate.html'}]其中模板为

<button class="btn btn-primary" ng-click="changeStatus(row.getProperty('id'),'{{row.getProperty(col.field) || switchStatus}}')">{{row.getProperty(col.field)}}</button>

编辑

myapp.filter('switchStatus', function() { return function(input) { return (input == 'STOPPED') ? 'STARTED' : 'STOPPED'; }; });

渲染的单元格是<button class="btn btn-primary ng-scope ng-binding" ng-click="changeStatus(row.getProperty('id'),'STOPPED')">STOPPED</button> 。 我期待第二个参数的STARTED。

Plunker :当点击STOPPED时,当前状态应该是STARTED

I created a cell template that depends on a filter, but the filter is not processed.

The cell is defined as {field:'status', displayName:'Status', cellTemplate: 'cell/statusCellTemplate.html'}] where the template is

<button class="btn btn-primary" ng-click="changeStatus(row.getProperty('id'),'{{row.getProperty(col.field) || switchStatus}}')">{{row.getProperty(col.field)}}</button>

EDIT

myapp.filter('switchStatus', function() { return function(input) { return (input == 'STOPPED') ? 'STARTED' : 'STOPPED'; }; });

The rendered cell is <button class="btn btn-primary ng-scope ng-binding" ng-click="changeStatus(row.getProperty('id'),'STOPPED')">STOPPED</button>. I expect STARTED for the second parameter.

Plunker: when clicking on STOPPED, the current status should be STARTED

最满意答案

data来自哪里? 我想你的意思是检查input是“停止”还是“启动”,如下所示:

app.filter('switchStatus', function() { return function(input) { var out = ""; if (input == 'STOPPED') { out = 'STARTED'; } else if (input == 'STARTED') { out = 'STOPPED'; } console.log(input + " " + out); return out; };

您可以通过编写以下内容来缩短过滤器:

app.filter('switchStatus', function() { return function(input) { return (input == 'STOPPED') ? 'STARTED' : 'STOPPED'; };

Where does data come from? I think you meant to check if input is 'STOPPED' or 'STARTED' like this:

app.filter('switchStatus', function() { return function(input) { var out = ""; if (input == 'STOPPED') { out = 'STARTED'; } else if (input == 'STARTED') { out = 'STOPPED'; } console.log(input + " " + out); return out; };

You could make your filter shorter by writing:

app.filter('switchStatus', function() { return function(input) { return (input == 'STOPPED') ? 'STARTED' : 'STOPPED'; };

更多推荐

本文发布于:2023-07-22 09:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219101.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   过滤器   细胞   模板   filter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!