0
我想在AngularJS
中顯示嵌套數組。但是,我無法讓它工作。角陣不會顯示嵌套數組
控制器:
$scope.selected_category = [];
$scope.categories = [];
$scope.getCategories = function() {
ItemService.getCategories().success(function(categories) {
$scope.categories = categories;
});
}
$scope.getCategories();
形式設置$scope.selected_category
<select class="form-control" ng-model="selected_category">
<option ng-repeat="category in categories" value="{{ category }}">{{ category.name }}</option>
</select>
所以......現在印刷{{ selected_category }}
顯示了subcategory
陣列內的預期陣列:
{
"id": "1",
"name": "clothing",
"subcategories": [
{
"id": "1",
"name": "jackets",
"item_category_id": "1"
},
{
"id": "2",
"name": "jeans",
"item_category_id": "1"
},
{
"id": "3",
"name": "sweaters",
"item_category_id": "1"
}
]
}
Hooowever,當我嘗試做selected_category.subcategories
我什麼都沒得到。這是爲什麼?
下面是與再現的問題plunker:http://plnkr.co/edit/AtqpXogmItdSupEZGt7R?p=preview
在你plunker你指定'category.name'而不是實際的類對象'selected_category' –