我使用ui-select而不是使用原生选择。这就是问题:
用户可以在位置数组中选择pick_up地址。如果没有地址,那么他可以添加新地址。我想使用ui-select-search输入字段来过滤select,如果在ui-select-choices中没有搜索的术语,则添加新的uniq地址。我有什么办法可以做到这一点吗?
这是我的代码:
<ui-select
ng-model="order.return_address"
theme="bootstrap"
tagging="order.return_address"
tagging-label="false"
reset-search-input="false"
on-select="itemSelected($select.selected)"
ng-required="isRequired"
refresh="updateValue('pick_up', $select.search)"
refresh-delay="900"
name="pick-up-location">
<ui-select-match>{{ $select.selected.title }}</ui-select-match>
<ui-select-choices repeat="address in pickUpAddresses | filter: {title: $select.search}" refresh="refreshItems($select.search)" refresh-delay="700">
{{ address.title }}
</ui-select-choices>
</ui-select>
附:我不想看到我在pickUpAddresses数组的输入字段中写的地址。
有一种方法可以使这项工作。因此,我需要将输入字段放在同一个地方并选择并添加到两个透明背景中。当您搜索是否从ui-select-choices中选择某些内容时,将没有问题。当你搜索并且ui-select-choices中没有项目时,你将这个属性添加到ui-select reset-search-input="false"
中,这将节省输入值。现在,您只需要从输入中获取值,该值为$select.search
,然后您在同一视图中选择并输入。此外,如果选择了某些内容,则需要重置$select.search
;如果选择了select的输入内容,则需要重置$select.selected
。