ui-select multiple存在问题。我需要设置默认值,但我不能这样做。我正在使用ui-select的自定义组件:
<input-form-wrapper input-ctrl="$ctrl">
<ui-select ng-if="$ctrl.isMultiple"
skip-focusser="true"
ng-model="$ctrl.uiSelectValue"
multiple
id="{{$ctrl.name}}"
name="{{$ctrl.name}}"
ng-change="$ctrl.onChange()"
ng-disabled="$ctrl.isDisabled"
theme="bootstrap">
<ui-select-match placeholder="{{$ctrl.placeholder}}">
{{($ctrl.shortMatchElement === 'true') ? $item.code : $item.uiSelectDisplayField}}
</ui-select-match>
<ui-select-choices
ui-disable-choice="option.status == 'disabled'"
repeat="option as option in $ctrl.options | filter: {uiSelectDisplayField: $select.search}">
<div ng-bind-html="option.uiSelectDisplayField"></div>
</ui-select-choices>
</ui-select>
</input-form-wrapper>
我正在以这种方式使用它:
<my-ui-select
json-options="$ctrl.myModelList"
is-disabled="$ctrl.myModelDisabled"
ng-model="$ctrl.myModel"
value-field="item"
empty-option="false"
is-multiple="true"
ng-change="$ctrl.onMyModelSelect()">
</my-ui-select>
我正在http请求的订阅功能中初始化组件:
for (let item in jsonResp) {
tmp.push({ value: jsonResp[item].description, id: jsonResp[mmt].id, code: jsonResp[item].code, status: jsonResp[item].isDisabled == "true" ? "disabled" : "", uiSelectDisplayField: jsonResp[item].description});
}
this.myModelList= tmp;
this.myModel.push(this.myModelList[0]);
虽然模型(this.myModel)已正确初始化,但输入中未显示该值。 代码中有错误吗?你能给我一个解决方案吗? 感谢
编辑: 这是my-ui-select的组件:
let myUiSelectComponent = {
'restrict': 'E',
'bindings': angular.merge({}, baseBindings, {
placeholder: "@",
valueField: "@",
displayField: "@",
jsonOptions: "<",
url: "<",
emptyOption: "<",
isDisabled: "<",
isMultiple: "<",
autoSelectFirstOption: "<",
onRefresh: "&",
onUpdateOptions: "&",
shortMatchElement: "@"
}),
template,
controller,
require: {
model: 'ngModel'
}
};
export default myUiSelectComponent;