我使用最新的 select2 api (select2-3.4.5),我的 html for select 2 看起来像这样。
<select ui-select2 id="select2-test" ng-model="mymodel.myTitle">
<option value="">Title</option>
<option ng-repeat="title in nameList" value="{{title.key}}">{{title.name}}</option>
</select>
我正在我的控制器中执行保存调用,以保存模型并重新加载保存的模型。这是在以下块内完成的。
$timeout(function(){
//if(!$scope.$$phase){
$scope.$apply(function(){
//update the model
//update code
})
//};
}, 50);
我所有的文本字段都加载了更新的数据,当我打印出 {{mymodel}} 时,我可以看到更新的模型。我在 $scope.$apply 中执行了保存和更新调用,目的是更新 dom 元素。
更新后,当我展开下拉列表 (select2) 时,我可以看到选择选项中选择的正确更新的值。
<option XXXX selected="selected">MYSELECTED</option>
但是 select2-container 有
<span class="select2-chosen">OLD</span> has the old value hence it is shown as the selected value.
这是选择 2 的问题还是我遗漏了什么?