我的问题与其他问题类似。但它是不同的。 请看下面的代码。
我想通过一组对象过滤数据。
这是片段
HTML
<div
ng-repeat="(key, value) in ledgerData.ledgers track by $index"
ledger-pop
index="$index"
ftype="ftypeUpdate"
itemdata="value"
acntlist="fltAccntList"
class='drEntryForm_{{$index}} pr'
name='drEntryForm_{{$index}}'
update-ledger="updateEntry(entry)"
novalidate
>
</div>
JS
$scope.ledgerDataata = {
"ForwardedBalance": {
"amount": 0,
"type": "CREDIT"
},
"creditTotal": 4008,
"debitTotal": 4008,
"balance": {
"amount": 4008,
"type": "CREDIT"
},
"ledgers": [
{
"transactions": [
{
"particular": {
"name": "Sarfaraz",
"uniqueName": "temp"
},
"amount": 1001,
"type": "DEBIT"
}
],
"description": "testing",
"tag": "testing"
},
{
"transactions": [
{
"particular": {
"name": "frnd",
"uniqueName": "frndafafaf14453422453110l26ow"
},
"amount": 2001,
"type": "CREDIT"
},
{
"particular": {
"name": "Rahul",
"uniqueName": "cake"
},
"amount": 3001,
"type": "DEBIT"
}
],
"description": "testing",
"tag": "testing",
}
]
}
我正在尝试按
过滤ng-repeat="(key, value) in ledgerData.ledgers track by $index | filter:{transactions[0]:{type: 'DEBIT'}}"
但是收到错误
提前感谢: - )
答案 0 :(得分:2)
您需要编写嵌套的ng-repeat来解决此问题。
ledgerData.ledgers中的事务数组的内部ng-repeat
<div ng-repeat="(keyOne, ledger) in ledgerData.ledgers track by $index">
{{ledger.description}}
<div ng-repeat="(keyTwo, transaction) in ledger.transactions | filter:{type:'DEBIT'}">
{{transaction.type}}
</div>
</div>
答案 1 :(得分:0)
实际上我得到了解决方案。
我几乎没有谷歌搜索,并为angularjs-filter
建立了一个图书馆。
Here is the link这是filter dirty works
非常好的插件以及如何使用它。
我是如何取得成功的:
<强> HTML 强>
ng-repeat="(key, value) in ledgerData.ledgers | pick: debitOnly track by $index"
<强> AngularJS 强>
$scope.debitOnly = (ledger) ->
'DEBIT' == ledger.transactions[0].type
是的。