【发布时间】:2018-03-13 11:58:15
【问题描述】:
我正在尝试遍历包含子类别的类别数组。
问题。我有这个类别数组:
$scope.categories = [{
"_id": 1,
"name": "Cat 1",
"categories": {
"_id": 11,
"name": "Cat 11",
"categories": {
"_id": 111,
"name": "Cat 111",
"categories": null
}
}
}, {
"_id": 2,
"name": "Cat 2",
"categories": null
}, {
"_id": 3,
"name": "Cat 3",
"categories": null
}];
如您所见,是一个包含子类别的对象数组,所以我知道我需要一个递归解决方案。
我需要将所有类别显示到 md-select 中(不需要将它分组,但它会很棒),我正在尝试这个:
<md-input-container class="md-block">
<label>Categories</label>
<md-select ng-model="selectedCategory">
<md-option ng-value="category._id" ng-repeat-start="category in categories">{{category.name}}</md-option>
<span ng-repeat-end ng-include="'subcategories'" ng-if="category.categories"></span>
</md-select>
</md-input-container>
<script type="text/ng-template" id="subcategories">
{{category.name}}
<md-option ng-value="category._id" ng-repeat-start="category in category.categories">{{category.name}}</md-option>
<span ng-repeat-end ng-include="'subcategories'" ng-if="category.categories"></span>
它部分工作,但不是预期的结果。
我想要什么?像这样的
我有什么? This code
如果需要更多详细信息,请告诉我。
谢谢
【问题讨论】:
-
我认为这是 angularjs 问题而不是 angular
-
对不起,是我的错
标签: angularjs recursion angularjs-ng-repeat angularjs-material