【发布时间】:2016-07-31 20:51:13
【问题描述】:
我正在使用带有过滤功能的 Angular ng-table 用于测试准备平台。我将测验结果存储为数据库中每个问题的0 or 1,但需要将它们显示为Correct 或Incorrect 给用户。
我可以通过 {{q.result == 1 ? 'Correct' : 'Incorrect'}} 做到这一点
但这也需要应用于过滤,也就是说,用户应该能够输入“正确”并过滤所有问题,q.result = 1。
<tr ng-repeat="q in $data">
<td title="'Correct/Incorrect'" filter="{ result: 'text'}" sortable="'q.result'" ng-class="{correct: q.result == 1, incorrect: q.result == 0}">
{{q.result == 1 ? 'Correct' : 'Incorrect'}}
</td>
我尝试更改 filter="{ result: 'text'} 以遵循上述三元约定,但它不起作用。
filter="{(result == 1 ? 'Correct' : 'Incorrect') : 'text'}" 给出错误:
Syntax Error: Token '(' invalid key at column 2 of the expression [{(result == 1 ? 'Correct' : 'Incorrect') : 'text'}] starting at [(result == 1 ? 'Correct' : 'Incorrect') : 'text'}].
我正在使用指令:
angular
.module('DDE')
.directive('results',['$rootScope', 'NgTableParams', function ($rootScope, NgTableParams) {
return {
restrict: 'AE',
scope: {},
transclude: true,
templateUrl: '/html/directives/results.html',
link: function(scope, elem, attr){
scope.questions = [];
/*
If user took a new test, show results
*/
scope.$on('show-results', function(event, args) {
scope.setData(args);
});
/*
Set question data
*/
scope.setData = function (args) {
console.log(args);
scope.questions = args;
scope.tableParams = new NgTableParams({}, { dataset: args});
};
}
}
}]);
Console.logging args 给出:
【问题讨论】:
-
你能在你的控制器中包含你创建表的部分吗?
-
@AlonEitan 见上文,这是一个指令
标签: javascript angularjs filter ngtable