[英]AngularJS deep filter through array in ng-repeat
我的問題看起來與其他問題相似。 但這是不同的。 請看下面的代碼。
我想按對象數組過濾數據。
這是片段
的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'}}"
但是出現錯誤
提前致謝 :-)
您需要編寫嵌套的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>
其實我找到了解決方案。
我幾乎沒有angularjs-filter
搜索,並為angularjs-filter
庫。
這是一個非常好的插件,用於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
而已。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.