【发布时间】:2013-11-19 02:18:03
【问题描述】:
我有一个 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,"name":"Capability"},"name":"Chemistry"},{"type":"category","id":1188,"categoryType":{"id":1183, "名称":"类别"},"名称":"键 观点 领导者"},{"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","id":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":"Technology"},"name":"Spotfire 网络 播放器"},{"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 应用程序"},{"type":"category","id":1201,"categoryType":{"id":1197,"name":"Function"},"name":"RAPIDE"},{" type":"category","id":1202,"categoryType":{"id":1197,"name":"Function"},"name":"iM - 肿瘤学"},{"type":"category","id":1203,"categoryType":{"id":1186,"name":"Capability"},"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' 中。
因此,对于该类别类型,我需要技术下拉列表,该下拉列表至少显示了 spotfire + 在该类别类型中的 JSON 文件中解析的任何其他内容。
然后是下一个 categoryType 的另一个下拉列表,依此类推。
【问题讨论】:
标签: angularjs select filter ng-options