[英]ng-repeat is not working
["2017-03-09 ": Array[6], "2017-03-10 ": Array[2]]
不是數組的語法。
數組是一系列以逗號分隔的值,如下所示:
['one', 'two', 'three']
如果要存儲一系列鍵值對,則應使用對象:
{
one: 1,
two: 2,
three: 3
}
你必須對這個對象使用兩個ng-repeat,因為你在對象中有數組,這些數組也包含對象。 所以首先ng-repeat遍歷對象的所有外部值,這個值是一個數組,因此內部循環遍歷每個對象的數組,並將對象的id值放入div中。
<div ng-repeat="inner in sortedOrders">
<div ng-repeat="total in inner">
<div class="col-75">{{total.id}}</div>
</div>
</div>
你有一個數組里面的數組,我從你的安慰圖像得到的。 為此,如果要顯示所有元素,則必須使用兩個ng-repeat循環。
我認為你正在創建這樣的數組:`
var specialArray = [];
// assigning values to corresponding keys
specialArray["Main"] = [{id:1}];
specialArray["Guide"] = [{id:2},{id:3}];
`
但角度模板無法識別(檢查我的plunker)。 嘗試使用普通對象(也可以使用plunker中的示例)。
在您的JSFidlle更改中:
$scope.sortedOrders= [];
to
$scope.sortedOrders= {};
並使用:
<div ng-repeat="(d,value) in sortedOrders">
{{value}}
</div>
示例: Plunker
在您的plunker中編輯,如:
<div ng-app>
<h2></h2>
<div ng-controller="TodoCtrl">
<div ng-repeat="d in sortedOrders">
<div ng-repeat="(f,value) in d">
{{value.id}}
</div>
</div>
</div>
和
$scope.sortedOrders=[]; to $scope.sortedOrders={};
您將在HTML頁面中獲取您的ID
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.