你证明什么:
HTML
<p>
<input type="text" ng-model="tags"
ui-select2="{tags: [{id:4, text:'red'},{id:2, text:'blue'},{id:8, text:'white'},{id:41, text:'green'},{id:13, text:'yellow'}]}" />
</p>
角UI
angular.module('app').controller('MainCtrl', function($scope) {
$scope.message = "Will load shortly...";
$scope.tags = [8, 2];
$scope.message = 'Loaded';
});
http://plnkr.co/edit/wUQq8P?p=preview
为什么它的工作呢?我不确定。也许有一种类型或东西没有正确加载。我从来没有使用Angular或Select2,所以我花了几次尝试才得以实现。
嗯。那么,复制你的代码到普拉克原来的样子,没有其他变化,我得到:
http://embed.plnkr.co/wUQq8P
所以我猜我要么不理解的问题,或者是别的地方在你的代码。
这是为原始工作例子中,使用可以很容易地与AJAX配对的方法:
HTML
<body ng-controller="MainCtrl">
<h4>{{message}}</h4>
<p>
<input type="text" ui-select2="options" ng-model="tags" />
</p>
</body>
角UI
angular.module('app').controller('MainCtrl', function($scope) {
$scope.message = "Will load shortly...";
$scope.options = {
tags: [
{id:4, text:'red'},
{id:2, text:'blue'},
{id:8, text:'white'},
{id:41, text:'green'},
{id:13, text:'yellow'}
]
};
$scope.tags = [8, 2];
$scope.message = 'Loaded';
});
http://plnkr.co/edit/wUQq8P?p=preview
这是如何渲染?一个隐藏的输入与类输入 - 大和ui-select2指令中的对象? – Galdo 2013-03-28 00:48:44
是的,这就是select2的工作方式 – foxx 2013-03-28 07:27:52