您好我使用Angualr来填充选择框,我正在获取一个标签列表,这些标签按如下方式组合在一起(我使用Laravel以JSON编码,以便我可以输出它友好的格式。);
在选定的
中填充的努力选项{
"5. XS":{"94":"01:00:00"},
"4. S":{"96":"02:00:00"},
"3. M":{"98":"04:00:00"},
"2. L":{"100":"07:00:00"},"
1. XL":{"102":"16:00:00"},
"0. XXL":{"104":"38:00:00"},
"105":"Estimate Required"
}
我还将所选的努力传回如下;
{"67","697"}
然后在角度我做以下事情:
Planning.groom(id)
.success(function (planning) {
$scope.tasks = planningtasks;
$scope.name = planning.name
$scope.id = planning.id;
$scope.auth = planning.auth;
$scope.effortTags = planning.effort;
});
然后在我看来,我会做以下事情;
<select ng-model="entity.selected_tags.effort"
ng-options="effort for effort in effortTags.effort">
</select>
但是我似乎无法显示选项,任何想法我做错了什么?
我希望使用选项组重新创建此下拉列表,但有些选项可能没有选项组,它们本身可能是一个选项,如上面选项&#34; Estimate Required& #34 ;;
我已经能够使用Laravel和jQuery。
答案 0 :(得分:2)
您需要重新构建基础JSON,例如像这样
$scope.effortTags = [
{ category: "5. XS", id: "94", value: "01:00:00" },
{ category: "4. S", id: "96", value: "02:00:00" },
{ category: "3. M", id: "94", value: "04:00:00" },
{ category: "2. L", id: "94", value: "07:00:00" },
{ category: "1. XL", id: "94", value: "16:00:00" },
{ category: "0. XXL", id: "94", value: "38:00:00" },
{ id: "105", value: "Estimate Required" }
];
然后你可以在模板中执行此操作:
<select ng-model="entity.selected_tags.effort"
ng-options="effort as effort.value group by effort.category for effort in effortTags">
</select>