2

從JSON調用的我的數據非常簡單。從JSON數據的陣列中的AngularJS過濾器陣列

我要篩選的所有數據,事件的ID是13

我的JSON從[...] $scope.things = things

[ 
    { 
    "id":"1", 
    "title":"title1", 
    "events":[ 
       {"id":"11", 
       "events11"}, 
       {"id":"12", 
       "events12"} 
       ] 
    },{ 
    "id":"2", 
    "title":"title2", 
    "events":[ 
       {"id":"11", 
       "events11"}, 
       {"id":"13", 
       "events13"} 
      ] 
    } 
] 

我試圖用顯示器提供:

<ion-item collection-repeat="thing in things | filter:{events.id:'13'}"> 
    {{thing.id}} 
</ion-item> 

回答

2

非常1日的事情以更正您的JSON格式,如events11,events12 & events13應該是這樣的鍵值對:"events": "11",「events」:「12」& "events": "13"

然後你可以使用像下面的深層過濾器。

標記

<ion-item collection-repeat="thing in things | filter:{events: {id:'13'}}"> 
    {{thing.id}} 
</ion-item> 

Plunkr here

+0

@JLRishe因爲避風港在json中沒有改變,所討論的JSON是無效的,你可以檢查附加的plunkr,雖然感謝人擡頭,歡呼:) –

+0

我有修復了破碎的JSON,但它一定沒有工作,因爲我的小提琴有Angular 1.0.1。我想深度過濾功能是在Angular的一些更新版本中添加的。 – JLRishe

+0

是的,如果我記得正確的話,它已經增加了1.3+以上 –

0

你可以直接過濾在實例化示波器變量時的控制器中:

$scope.things = things.filter(obj => obj.id==='13'); 
0

您可以用NG-如果和一個輔助函數試試:

<ion-item collection-repeat="thing in things" ng-if="getEventInThing(thing, '13')"> 
    {{thing.id}} 
</ion-item> 

下面的函數將與給定id返回的情況下,如果存在的話:你需要

$scope.getEventInThing = function(thing, eventId) { 
return thing.events.find(function(event) { 
    return event.id===eventId; 
}); 
} 
-1
<ion-item collection-repeat="thing in things"> 
    <span ng-repeat="event in thing.events" ng-if="event.id='13'" 
     {{thing.id}} 
</ion-item> 

基本上兩個循環與NG-如果內部循環,以檢查是否偶數的id是13

+0

'item.id =='13''是什麼意思? –

+0

我的不好,只是一個錯字,現在改變了它 –

+0

OP想要過濾出內部事件ID .. –