angularjs – 对嵌套字段的ngTable过滤
发布时间:2020-12-17 07:51:39 所属栏目:安全 来源:网络整理
导读:我在ng-table中有一张发票清单,希望能够过滤嵌套属性. json看起来像这样; [ { id: 1,date: "20/03/2014",no: "1",client: { fullname: "ABC Catering" } }] 我的观点看起来像这样 table ng-table="tableParams" show-filter="true" class="table" tr class='
我在ng-table中有一张发票清单,希望能够过滤嵌套属性. json看起来像这样;
[ { id: 1,date: "20/03/2014",no: "1",client: { fullname: "ABC Catering" } } ] 我的观点看起来像这样 <table ng-table="tableParams" show-filter="true" class="table"> <tr class='listing' ng-repeat="invoice in $data"> <td data-title="'Invoice No.'" sortable="'no'" filter="{'no':'text'}"> {{invoice.no}} </td> <td data-title="'Date'" sortable="'date'" filter="{'date':'text'}"> {{invoice.date}} </td> <td data-title="'Client'" sortable="'client.fullname'" filter="{'client.fullname':'text'}"> {{invoice.client.fullname}} </td> <td> <a href="/api#/invoices/{{invoice.id}}">Show</a> <a href="/api#/invoices/{{invoice.id}}/edit">Edit</a> <a href="" ng-confirm-click="destroy(invoice.id)">Delete</a> </td> </tr> </table> 我想让client.fullname的过滤工作.如何过滤嵌套属性? 更新 我找到了一个解决方法,我将嵌套字段放入非嵌套的JSON元素中,在上面的示例中,我创建了一个JSON [‘client_name’]元素并将其分配给rails模型中的client.fullname.然后过滤器工作,因为它没有嵌套. 仍在寻找一种方法,我可以做到没有这个工作.
您可以对要从JSON响应中筛选的任何内容使用
$filter .
HERE是如何在嵌套的JSON元素上进行过滤的人为例子.示例代码取自ng-table’s usage with filters的示例之一. 应用程序中需要注意的主要部分是 $scope.tableParams = new ngTableParams({ page: 1,count: 10,filter: { 'client': 'Bo' //Sample filter } },{ total: data.length,getData: function($defer,params) { //Note the usage of built in angular filter //which is injected in the app var orderedData = params.filter() ? $filter('filter')(data,params.filter()) : data; $scope.users = orderedData.slice((params.page() - 1) * params.count(),params.page() * params.count()); params.total(orderedData.length); $defer.resolve($scope.users); } }); Plunker按预期工作(如果我的要求正确).如果那不是你想要的东西,请大声喊叫. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |