我尝试了 AngularJS ui-select 演示应用程序:https ://github.com/angular-ui/ui-select2/tree/master/demo进行多选。我尝试的具体示例是具有预定义值的多选。最初,它加载两个预选状态。单击条目时,下拉菜单显示未定义。并且模型具有两个字符的状态名称。我错过了什么吗?
plunker 链接:http ://plnkr.co/edit/IeWSZX2MDq1GfXbm3hQB
html:
<input type="text" style="width:300px" ui-select2="multi" ng-model="multi2Value" />
片段:
var states = [
{ text: 'Alaskan/Hawaiian Time Zone', children: [
{ id: 'AK', text: 'Alaska' },
{ id: 'HI', text: 'Hawaii' }
]},
{ text: 'Pacific Time Zone', children: [
{ id: 'CA', text: 'California' },
{ id: 'NV', text: 'Nevada' },
{ id: 'OR', text: 'Oregon' },
{ id: 'WA', text: 'Washington' }
]}, ...}
$scope.multi2Value = [
{ id: 'CT', text: 'Connecticut' },
{ id: 'DE', text: 'Delaware' }];
$scope.multi = {
multiple: true,
query: function (query) {
query.callback({ results: states });
},
initSelection: function (element, callback) {
var val = $(element).select2('val'),
results = [];
for (var i=0; i<val.length; i++) {
results.push(findState(val[i]));
}
callback(results);
}
};