2
我正在嘗試使用對象數組進行過濾。但我沒有按照我的要求得到答案。如何從主要對象值過濾對象數組
對象我循環但有3個步驟的數組。我試圖過濾它們並在li
元素中顯示,但無法正常工作。只有第一步對我有效。
數組爲:「姓名,
子項目and
Contracts`(所有嵌套在主對象的內部)
這裏是我的嘗試:
<div class="section filter1">
<ul>
<li ng-repeat="value in values"> {{value.Name}}</li>
</ul>
</div>
<div class="section filter2">
<ul>
<li ng-repeat="value in values | SubProjects"> {{$index}}</li>
</ul>
</div>
<div class="section filter3">
<ul>
<li ng-repeat="value in values | SubProjects | Contracts"> {{value.Name}}</li>
</ul>
</div>
對象樣本:
{
"Id": "1",
"Name": "Khalifa International Stadium",
"SubProjects": [
{
"Contracts": [
{
"CompletedPercentage": 0,
"Id": "583",
"Name": "LP/C21/145",
"Phase": null
},
{
"CompletedPercentage": 0,
"Id": "529",
"Name": "KP/B21/134",
"Phase": null
},
{
"CompletedPercentage": 0,
"Id": "575",
"Name": "LP/C21/142",
"Phase": null
}
],
"Id": "2",
"Name": "Energy Center"
},
不知道你所說的「價值觀價值|子項目」的意思是過濾器語法是不同的,反正檢查這兩個來源https://docs.angularjs.org/api/ng/filter/filter和https: //www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=angularjs%20filter%20nested%20array –
我想從使用過濾器的嵌套數組中檢索對象,這是不可能的? – 3gwebtrain
一切皆有可能!檢查相同問題的例子,嘗試一些事情,至少過濾主要數組。用問題創建jsFiddle,然後有人可以幫助你。 –