JSON响应如何显示在HTML JSON响应选择使用AngularJS
[{"parentCategoryName":"Automobiles","subCategories":[[{"subCategoryID":1,"subCategoryName":"Car Parts & Accessories"},{"subCategoryID":2,"subCategoryName":"Campervans & Caravans"},{"subCategoryID":3,"subCategoryName":"Motorbikes & Scooters"},{"subCategoryID":4,"subCategoryName":"Motorbike Parts & Accessories"},{"subCategoryID":5,"subCategoryName":"Vans, Trucks & Plant"},{"subCategoryID":6,"subCategoryName":"Wanted"}]]}]
答案应该是请参考下面的图像
I want to display the above json response like this
HTML代码
<select name="category-group" id="category-group" class="form-control">
<option value="0" selected="selected"> Select a category...</option>
<option value="Vehicles" style="background-color:#E9E9E9;font-weight:bold;" disabled="disabled"> - Vehicles -
</option>
<option value="Cars"> Cars</option>
<option value="Commercial vehicles"> Commercial vehicles</option>
<option value="Motorcycles"> Motorcycles</option>
<option value="Motorcycle Equipment"> Car & Motorcycle</option>
</select>
AngularJS控制器
$scope.getCategory = function() {
ApiService.getCategory().then(function (response) {
$scope.categoriesBody = response;
console.log($scope.categoriesBody);
});
}
感谢
我们不是在这里做你的工作。至少你必须展示你的尝试。 – Malkev
兄弟我累了很多,但不工作:( –
@SalihMohamed根据你给的形象,我相信你应该看看http://angular-ui.github.io/ui-select/。看看“Group by”,“Group Filter”features –