我有2个使用ui-select2的下拉列表
<label class="control-label" for="MakeSelect">Make </label>
<select class="form-control col-md-2" id="MakeSelect" name="make" ui-select2
ng-model="carDetails.make">
<option ng-if="!carDetails.make" value="">[SELECT]</option>
<option ng-repeat="make in makes" value="{{ make }}">{{ make}}</option>
</select>
</div>
<div class="col-md-5">
<label class="control-label" for="ModelSelect">Model </label>
<select class="form-control col-md-2" id="ModelSelect" name="make" ui-select2
ng-model="carDetails.model">
<option ng-repeat="model in models" value="{{ model }}">{{ make}}</option>
</select>
在下拉列表“ Makes”中选择一个值之后,我激活了一个手表,该手表在其中装载了“ Models”下拉列表的内容。然后,为了刷新GUI中的下拉列表内容,我调用$ scope。$ digest():
$scope.$watch('carDetails.make', function (make) {
console.log('selected make is: ' + make);
if (make == "") {
return;
}
Parse.Cloud.run('getCarModels', {'Make': make}, {
success: function (results) {
$scope.parseModels = results.resultSet;
$scope.models = results.distinctModels;
$scope.$digest();
},
error: function () {
console.log("Error: Failed to load models");
console.log(Parse.Error);
}
});
问题在于,使用$ digest,第一个下拉列表的选定值将变为空值,否则,它不会刷新视图。
有什么建议吗?
他们都指向同一个范围模型carDetails.make。因此,当然,第一个将变为null,因为第二个下拉列表将carDetails.make设置为null。另外,尽管您应该使用$ scope。$ apply,但我认为您不需要使用摘要。但是,angularjs应该仍然运行摘要。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句