2015-10-17 95 views
0

我在嘗試使用選擇值過濾列的ngTable example。 HTML代碼(表部分)在ngTable中使用選擇過濾器

<table ng-table="tableParams" class="table" show-filter="true"> 
    <tbody> 
    <tr ng-repeat="row in $data"> 
     <td data-title="'Name'" filter="{name: 'select'}" filter-data="names" sortable="'name'">{{ row.name }}</td> 
     <td data-title="'Age'" filter="{age: 'text'}" sortable="'age'">{{ row.age }}</td> 
    </tr> 
    </tbody> 
</table> 

Javascript代碼

var app = angular.module('ngTableApp', ['ngTable']) 
     .controller('selectFilterController', function($scope, $filter, $q, NgTableParams) { 
     var data = [{name: "Moroni", age: 50}, 
        {name: "Tiancum", age: 43}, 
        {name: "Jacob", age: 27}, 
        {name: "Nephi", age: 29}, 
        {name: "Enos", age: 34}, 
        {name: "Tiancum", age: 43}, 
        {name: "Jacob", age: 27}, 
        {name: "Nephi", age: 29}, 
        {name: "Enos", age: 34}, 
        {name: "Tiancum", age: 43}, 
        {name: "Jacob", age: 27}, 
        {name: "Nephi", age: 29}, 
        {name: "Enos", age: 34}, 
        {name: "Tiancum", age: 43}, 
        {name: "Jacob", age: 27}, 
        {name: "Nephi", age: 29}, 
        {name: "Enos", age: 34} 
       ]; 
     $scope.names = ['Moroni', 'Enos', 'Nephi']; 
     $scope.tableParams = new NgTableParams({page: 1, count: 10}, {dataset: data}); 

     }) 

當我運行這段代碼plunker,列 '名稱' 的選擇值是空白。

example

選擇篩選器將通過調用列定義的fetchData功能獲取其數據。

但是,有一個名爲在該示例代碼中沒有fetchData功能。我很困惑,因爲這裏有什麼問題?

+0

入住plunker錯誤.. – Rayon

+0

@RayonDabre看起來像plunker的問題。我的本地機器中的相同代碼顯示沒有錯誤(但在我的問題中提到了相同的問題)。 – rajendra

回答

0

example我要指出的是濾波器數據屬性在HTML(用於選擇值)使用的NG-表的格式是以下形式的對象陣列。

$scope.names = [{id: "", title: ""}, {id: 'Moroni', title: 'Moroni'}, {id: 'Enos', title: 'Enos'}, {id: 'Nephi', title: 'Nephi'}]; 

更新plunker

0

應該這樣寫:

$scope.names = [{"id": "", "title": ""}, {"id": "Moroni", "title": "Moroni"}];