是否可以使用单个 select 但将模型作为数组获取
Is it possible to use single select but get model as an array
我正在使用 angular-ui 的 select2 组件,我希望我的模型具有一致的值,无论我使用的是单个 select 还是多 select.
目前,如果我使用单个 select,模型只设置为一个值,当使用多个 select 时,模型是一组值。
IE单机select:(非数组模型)
<ui-select ng-model="model.value" theme="bootstrap">
<ui-select-match>{{$select.selected.title}}</ui-select-match>
<ui-select-choices repeat="choice.title as choice in choices | filter: $select.search">
<div ng-bind-html="choice.title | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
或多:(数组模型)
<ui-select multiple ng-model="model.value" theme="bootstrap">
<ui-select-match>{{$item.title}}</ui-select-match>
<ui-select-choices repeat="choice.title as choice in choices">
<div ng-bind-html="choice.title"></div>
</ui-select-choices>
</ui-select>
我尝试使用多个,并添加了 length="1" 属性,但这仍然将 multiselect 样式应用于 select 框。
即使在单个 select 上,是否有可能从 select2 获取数组模型?
如何通过将 ng-model="model.value" 更改为 ng-model="model.value[0]" 来将模型设置为数组中的第一个位置?我相信这应该有效。如果不是,请尝试先将控制器中的模型初始化为空数组。 ($scope.model = [];)
<ui-select ng-model="model.value[0]" theme="bootstrap">
<ui-select-match>{{$select.selected.title}}</ui-select-match>
<ui-select-choices repeat="choice.title as choice in choices | filter: $select.search">
<div ng-bind-html="choice.title | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
我正在使用 angular-ui 的 select2 组件,我希望我的模型具有一致的值,无论我使用的是单个 select 还是多 select.
目前,如果我使用单个 select,模型只设置为一个值,当使用多个 select 时,模型是一组值。
IE单机select:(非数组模型)
<ui-select ng-model="model.value" theme="bootstrap">
<ui-select-match>{{$select.selected.title}}</ui-select-match>
<ui-select-choices repeat="choice.title as choice in choices | filter: $select.search">
<div ng-bind-html="choice.title | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
或多:(数组模型)
<ui-select multiple ng-model="model.value" theme="bootstrap">
<ui-select-match>{{$item.title}}</ui-select-match>
<ui-select-choices repeat="choice.title as choice in choices">
<div ng-bind-html="choice.title"></div>
</ui-select-choices>
</ui-select>
我尝试使用多个,并添加了 length="1" 属性,但这仍然将 multiselect 样式应用于 select 框。
即使在单个 select 上,是否有可能从 select2 获取数组模型?
如何通过将 ng-model="model.value" 更改为 ng-model="model.value[0]" 来将模型设置为数组中的第一个位置?我相信这应该有效。如果不是,请尝试先将控制器中的模型初始化为空数组。 ($scope.model = [];)
<ui-select ng-model="model.value[0]" theme="bootstrap">
<ui-select-match>{{$select.selected.title}}</ui-select-match>
<ui-select-choices repeat="choice.title as choice in choices | filter: $select.search">
<div ng-bind-html="choice.title | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>