【发布时间】:2014-08-28 10:08:09
【问题描述】:
我正在尝试设置 select2 下拉菜单的初始值。问题是该值是一个对象。
我试着弄乱initSelection,但我什至无法让它调用它。我将debugger 放入其中,但没有任何反应。 ngSelected 也不起作用 :(
我发了plunker。
标记
<select ui-select2="opt"
ng-change="save()"
ng-model="chosen"
data-placeholder="Choose">
<option value=""></option>
<option ng-repeat="item in list" value="{{item}}">{{item.a + ' ' + item.b}}</option>
</select>
控制器
app.controller('MainCtrl', function($scope) {
$scope.selected = {a: 2, b: 22};
$scope.list = [{a: 1, b: 11}, {a: 2, b: 22}];
$scope.opt = {
allowClear: true,
initSelection: function (elem, callback) {
debugger; // this never triggers... :(
}
};
$scope.save = function() {
$scope.pre = $scope.chosen;
};
});
我希望在下拉列表中选择$scope.selected 中的值。
【问题讨论】:
标签: angularjs jquery-select2 ui-select2