gpt4 book ai didi

javascript - angularjs ng-repeat cascading Dropdown不更新

转载 作者:行者123 更新时间:2023-11-27 22:53:19 25 4
gpt4 key购买 nike

我在使用 Angularjs 时遇到这个问题我正在创建如下所示的级联下拉列表

            <div class="col-sm-2 pr10">
<select class="PropertyType" ng-controller="LOV" ng-init="InitLov(140)" ng-model="PropertyType" ng-change="update(PropertyType)" >
<option value="" selected="selected" disabled="disabled"> {{type ? type: 'Property Type'}} </option>
<!-- <option value="">-- Select Type --</option>-->
<option ng-repeat="Lov in LovList" value="{{Lov.Value}}" >{{Lov['Lable'+Lang]}} </option>
</select>
</div>
<div class="col-sm-2 pr10">
<select class="PropertySubType" ng-controller="LOV" ng-model="PropertySubType" >
<option value="" selected="selected"disabled="disabled" >{{subType ? subType: 'Property Sub Type'}}</option>
<!-- <option value="">-- Select Sub Type --</option> -->
<option ng-repeat="Sub in SubType" value="{{Sub.Value}}" >{{Sub['Lable'+Lang]}} </option>
</select>
</div>

和 Angular 文件:

            $scope.update = function (id) {
$http.post("API/WebsiteService.asmx/getSubPropertyLov", { type: id }).success(function (data) {

debugger;
var rr = eval('(' + data.d + ')');
$scope.SubType = rr.result;

});
}

API返回数据,SubType范围获取它,但它不会改变下拉数据(PropertySubType),*该功能在LOV Controller 内部。

最佳答案

不要在每个选择上重复ng-controller="LOV",这样它们都会获得不同的范围。将两个选择放在同一 Controller 的范围内。

也不要使用 ngRepeat,使用 ngOptions:

<div ng-controller="LOV">
<div class="col-sm-2 pr10">
<select class="PropertyType"
ng-init="InitLov(140)"
ng-model="PropertyType"
ng-change="update(PropertyType)"
ng-options="Lov.Value as Lov['Lable' + Lang] for Lov in LovList">
<option value="" selected="selected" disabled="disabled"> {{type || 'Property Type'}} </option>
</select>
</div>
<div class="col-sm-2 pr10">
<select class="PropertySubType"
ng-options="Sub.Value as Sub['Lable' + Lang] for Sub in SubType"
ng-model="PropertySubType">
<option value="" selected="selected" disabled="disabled">{{subType || 'Property Sub Type'}}</option>
</select>
</div>
</div>

关于javascript - angularjs ng-repeat cascading Dropdown不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37860691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com