我有一个 categoryTypes 列表,每个 categoryType 都有一个类别列表,我在一个下拉列表中显示它们,用户可以从中选择多个项目,所做的选择将过滤视图中显示的应用程序(这是一个内部应用商店)
这是我正在使用的 JSON 文件。
[{"type":"category","id":1181,"categoryType":{"id":1180,"name":"Technology"},"name":"Spotfire"},{"type": "category","id":1182,"categoryType":{"id":1180,"name":"Technology"},"name":"PipelinP"},{"type":"category","id ":1184,"categoryType":{"id":1183,"name":"Category"},"name":"IBSI"},{"type":"category","id":1185,"categoryType ":{"id":1183,"name":"Category"},"name":"Clin"},{"type":"category","id":1187,"categoryType":{"id" :1186,"名称":"Capability"},"name":"Chemistry"},{"type":"category","id":1188,"categoryType":{"id":1183,"name":"Category"},"name ":"关键意见领袖"},{"type":"category","id":1189,"categoryType":{"id":1183,"name":"Category"},"name":"Pnts "},{"type":"category","id":1190,"categoryType":{"id":1183,"name":"Category"},"name":"CI"},{"type ":"category","id":1191,"categoryType":{"id":1180,"name":"Technology"},"name":"VantageP"},{"type":"category", “身份证”:1192,"categoryType":{"id":1183,"name":"Category"},"name":"Targets"},{"type":"category","id":1193,"categoryType":{" id":1186,"name":"能力"},"name":"信息科学"},{"type":"category","id":1194,"categoryType":{"id":1186, "name":"Capability"},"name":"DMP"},{"type":"category","id":1195,"categoryType":{"id":1180,"name":"技术"},"name":"Spotfire Web Player"},{"type":"category","id":1196,"categoryType":{"id":1186,"name":"Capability"},"name":"PredictiveS"},{"type":"category","id":1198,"categoryType":{"id":1197,"name":"Function"},"name":"PharmD" },{"type":"category","id":1199,"categoryType":{"id":1197,"name":"Function"},"name":"iM - CV/GI"}, {"type":"category","id":1200,"categoryType":{"id":1180,"name":"Technology"},"name":"Mobile Apps"},{"type": "category","id":1201,"categoryType":{"id":1197,"name":"Function"},"name":"RAPIDE"},{"type":"category","id ":1202,"categoryType":{"id":1197,"name":"Function"},"name":"iM - Oncology"},{"type":"category","id":1203,"categoryType":{"id" :1186,"name":"能力"},"name":"Clin"}]
但是因为管理员可以将 categoryTypes 和类别添加到任何类型,所以需要动态创建下拉列表,因为它们是硬编码的。每个类别类型都需要有一个新的下拉列表。
所以我能做的就是将所有类别显示在一个下拉列表中,按类别类型分组;
<select class="form-control" multiple class="span4 chzn-select" chosen="myCategories" data-placeholder=" " ng-model="c" ng-options="c.name group by c.categoryType.name for c in myCategories">
我创建了工厂来获取类别;
.factory('categoryFactory', function ($resource) {
return $resource(
'/resources/appstore/categories'
);
})
控制器看起来像这样;
$scope.myCategories = [];
categoryFactory.query(function (d) {
$scope.myCategories = d;
});
因此,以 JSON 的第一行为例。
'Spotfire' 的类别在 categoryType 'Technology' 中。
所以对于那个categorytype,我需要技术的下拉列表,它至少显示spotfire +在那个categoryType的JSON文件中解析的任何其他内容。
然后是下一个 categoryType 的另一个下拉列表,依此类推。