【发布时间】:2015-11-03 03:51:32
【问题描述】:
我正在尝试使用 null 选项构建双重选择。
根据第一个选择的选项过滤一个选择。 我遇到的问题是即使在过滤后我也想保留第一个“空”行。
我根据我看到的 null 选项的解决方案制作了一个 plunker。 这是笨蛋:demo
我正在尝试选择一个国家和城市,将“null”选项 (anyCity) 保留为可选选项。实现这一目标的最佳方法是什么?
(我原来的问题是双重过滤——>选择一个城市也过滤国家)
HTML:
<body ng-controller="DemoCtrl">
<h3>Countries</h3>
<p>Selected: {{country.selected || (country.selected === null ? 'null' : '')}}</p>
<ui-select ng-model="country.selected" theme="bootstrap" ng-disabled="disabled" style="width: 300px;">
<ui-select-match placeholder="Select or search a country in the list...">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="country in countries | filter: $select.search" null-option="anyCountry">
<span ng-bind-html="country.name | highlight: $select.search"></span>
<small ng-bind-html="country.code | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>
<h3>Cities</h3>
<p>The loose-null option treats undefined the same as null.</p>
<p>Selected: {{country2.selected || (country2.selected === null ? 'null' : '')}}</p>
<ui-select ng-model="country2.selected" theme="bootstrap" ng-disabled="disabled" style="width: 300px;">
<ui-select-match placeholder="Select or search a city in the list...">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="city in cities | filter: {country: country.selected.code}" null-option="anyCity" loose-null>
<span ng-bind-html="city.name | highlight: $select.search"></span>
<small ng-bind-html="city.code | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>
</body>
</html>
【问题讨论】:
标签: javascript angularjs ui-select