我创建了一个依赖于过滤器的单元格模板,但不处理过滤器。
该单元格定义为{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'; };更多推荐
发布评论