在嵌套领域ngTable过滤

编程入门 行业动态 更新时间:2024-10-28 16:24:54
本文介绍了在嵌套领域ngTable过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有在NG表的发票清单,并希望能够在嵌套的属性进行过滤。 JSON的是这样的;

I've got a list of invoices in ng-table and would like to be able to filter on a nested attribute. The json looks like this;

[ { id: 1, date: "20/03/2014", no: "1", client: { fullname: "ABC Catering" } } ]

我认为这个样子的。

My view look like this

<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工作。如何在嵌套属性过滤器?

I would like to get the filtering working for client.fullname. How do I filter on nested attributes?

更新

我发现身边,我只是把嵌套领域到非嵌套的JSON元素,在上面的例子中,我创建一个JSON ['CLIENT_NAME']元素,并为其分配一个工作轨道模型中client.fullname 。然后过滤器的工作原理,因为它不是嵌套。

I've found a work around where I just put the nested field into a non-nested JSON element, in the above example I create a JSON['client_name'] element and assign it to client.fullname within the rails model. Then the filter works as it's not nested.

还在寻找一个方式,我可以不用做这项工作各地。

Still looking for a way in which I could do without this work around.

推荐答案

您可以使用 $过滤器 上任何你想从JSON响应滤波器上

You can use $filter on anything you want to filter on from the JSON response.

这里 是一个人为的例如如何过滤可以嵌套JSON元素上进行。样品code为从纳克表与过滤器用法的例子之一作出。

HERE is a contrived example of how filtering can be done on nested JSON element. Sample code is taken from one of the example of ng-table's usage with filters.

主要部分应用需要注意的是

Main part to note in the app is

$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按预期工作(如果我得到你的要求是正确的)。给留言如果这东西是不是你的目标所在。 :)

Plunker works as expected (if I got your requirement correct). Give a shout if that something that is not what you are aiming at. :)

更多推荐

在嵌套领域ngTable过滤

本文发布于:2023-11-26 05:52:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632893.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   领域   ngTable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!