2016-04-10 14 views
0

私は角を使用していますng-tableテスト準備プラットフォームのためのフィルタリング。私はDBに質問ごとに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'}を上記の3慣行に従って変更しようとしましたが、動作しません。

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'}]. 

私はディレクティブを使用しています:argsをConsole.logging

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}); 
       }; 
      } 
     } 
}]); 

ができます:

enter image description here

+0

コントローラにテーブルを作成する場所を含めることはできますか? –

+0

@AlonEitan上記参照、それは指令です – Growler

答えて

0

このモジュールのドキュメントは、これは私がソートやテーブル

scope.tableParams = new NgTableParams({}, { 
    total: args.length, 
    data: args, 
    getData: function ($defer, params) { 
     var orderedData = params.filter() ? $filter('filter')(scope.questions, params.filter()) : scope.questions; 
     orderedData = params.sorting() ? $filter('orderBy')(orderedData, params.orderBy()) : orderedData; 
     params.total(orderedData.length); 
     $defer.resolve(orderedData); 
    } 
}); 

をフィルタリングする方法であり、あなたがfilter="{ result: 'text'}を使用してフィルタを設定し、またあなたの指示に$filterを注入する必要があり、かなり安っぽいです。

関連する問題