[英]AngularJS drop down 2 level deep
Following are returned Json data from server: 以下是从服务器返回的Json数据:
$scope.cities = response.data;
is: 是:
0: {id: 1, name: "Malaysia",…}
city: [{id: 1, country_id: 1, city: "Kuala Lumpur"}, {id: 2, country_id: 1, city: "Selangor"},…]
0: {id: 1, country_id: 1, city: "Kuala Lumpur"}
city: "Kuala Lumpur"
country_id: 1
id: 1
1: {id: 2, country_id: 1, city: "Selangor"}
city: "Selangor"
country_id: 1
id: 2
id: 1
name: "Malaysia"
1: {id: 2, name: "Singapore", city: [{id: 11, country_id: 2, city: "Singapore"}]}
city: [{id: 11, country_id: 2, city: "Singapore"}]
id: 2
name: "Singapore"
and in my views 在我看来
<ui-select ng-model="cities.selected" theme="bootstrap">
<ui-select-match placeholder="Select City">
{{$select.selected.name}}
</ui-select-match>
<ui-select-choices repeat="item in cities | filter: $select.search">
<div ng-bind-html="item.city.city | highlight: $select.search"</div>
</ui-select-choices>
</ui-select>
But I cant render the following way of drop down: 但是我无法提供以下下拉方式:
-Malaysia
- Kuala Lumpur
- Selangor
-Singapore
-Singapore
Thanks!! 谢谢!!
Try this. 尝试这个。 Use nested ng-repeat and bind it in li tag. 使用嵌套的ng-repeat并将其绑定到li标签中。
<ui-select-choices repeat="item in cities | filter: $select.search">
<div ng-bind-html="item.city.city | highlight: $select.search"</div>
<li ng-repeat="data in item.city">
{{data.city}}
</li>
</ui-select-choices>
try this 尝试这个
<ui-select ng-model="cities.selected" theme="bootstrap">
<ui-select-match placeholder="Select City">
{{$select.selected.name}}
</ui-select-match>
<ui-select-choices ng-repeat="item in cities | filter: $select.search">
<div ng-bind-html="item.name| highlight: $select.search"</div>
<li ng-repeat="data in item.city">
{{data.city}}
</li>
</ui-select-choices>
</ui-select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.