doulu3865
2016-09-29 07:08
浏览 127
已采纳

如何使用AngularJS在HTML select中显示json响应

Json Response

[{"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"}]]}]

Answer should be Please see below image

I want to display the above json response like this

HTML Code

 <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 &amp; Motorcycle</option>
    </select>

AngularJS Controller

$scope.getCategory = function() {
            ApiService.getCategory().then(function (response) {
                $scope.categoriesBody = response;   
                console.log($scope.categoriesBody);

            }); 
        }

Thanks

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题