angular.js - angularjs 动态请求的select options,数据绑定不上去
巴扎黑
巴扎黑 2017-05-15 16:54:20
0
3
711


如图 ajax 获取的地域信息

ng-modal绑定的数据并不能正确显示。
目前自我判断是$scope.city数据绑定发生在拉去options列表之前,请问如何激活显示?


UPDATE:补充一下问题 我的代码是这样的

<select name="" id="province" ng-model="group.province.id" ng-change="getCity()">
    <option value="">请选择</option>
    <option value="{{pr.id}}" ng-repeat="pr in prs">{{pr.name}}</option>
</select>
<select name="" id="city" ng-model="group.city.id" ng-change="getDistrict()">
    <option value="">请选择</option>
    <option value="{{city.id}}" ng-repeat="city in citys">{{city.name}}</option>
</select>
<select name="" id="district" ng-model="group.district.id" ng-change="getCircle()">
    <option value="">请选择</option>
    <option value="{{district.id}}" ng-repeat="district in districts">{{district.name}}</option>
</select>

我试了用你的方法直接用options的repeat的对象作为ng-model的对象 好像行不通会报错

巴扎黑
巴扎黑

reply all(3)
黄舟

The information you provided is not specific enough, but I guess this is the reason:

In controller:

$scope.city = {};

In view:

<input ng-model="city.data" />

<li ng-repeat="c in city.data">...</li>

The model must be bound with the city attribute

迷茫

1. Process the data you want to use on the routing resolve.
2. It is very bad to use $scope.$watch(expression)对你要显示的数据模型进行监测,当数据从远程拉取下来的时候,可以实时更新(不推荐这种方法,在控制器中使用$scope.$watch() on a controller ).

小葫芦

To add to the question, my code is like this

<select name="" id="province" ng-model="group.province.id" ng-change="getCity()">
    <option value="">请选择</option>
    <option value="{{pr.id}}" ng-repeat="pr in prs">{{pr.name}}</option>
</select>
<select name="" id="city" ng-model="group.city.id" ng-change="getDistrict()">
    <option value="">请选择</option>
    <option value="{{city.id}}" ng-repeat="city in citys">{{city.name}}</option>
</select>
<select name="" id="district" ng-model="group.district.id" ng-change="getCircle()">
    <option value="">请选择</option>
    <option value="{{district.id}}" ng-repeat="district in districts">{{district.name}}</option>
</select>

I tried using your method to directly use the repeat object of options as the object of ng-model. It seems that it doesn’t work and an error will be reported

@emj365

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template