【发布时间】:2018-10-26 18:07:33
【问题描述】:
我正在尝试创建一个表单,该表单捕获国家/州/城市的嵌套流并推送到 ng-repeat 对象。将其添加到中继器后,我希望可以选择编辑该嵌套选择。
我不明白将嵌套对象添加到中继器后 ngModel 和 ngOptions 是如何发挥作用的。我尝试了几个选项都没有成功。
我添加了一个 plunker 来帮助解释这个问题: http://next.plnkr.co/edit/FWLa3ErI83JLR4Jy
这是有问题的部分无法正常工作:
HTML
<tr ng-repeat="location in locations">
<td>
<select ng-show="editable" name='CountryName' id="CountryName" class="form-control" ng-model="country" ng-options="country as country.CountryName for country in countries"
required>
<option value="" disabled>Select</option>
</select>
<span ng-show="!editable">{{location.CountryName}}</span>
</td>
<td>
<select ng-show="editable" name='StateName' required id="StateName" class="form-control" ng-disabled="states.length == 0" ng-model="state" ng-options="state as state.StateName for state in states">
<option value="" disabled>Select</option>
</select>
<span ng-show="!editable">{{location.StateName}}</span>
</td>
<td>
<select ng-show="editable" name='CityName' required id="CityName" class="form-control" ng-disabled="cities.length == 0" ng-model="city" ng-options="city as city.CityName for city in cities">
<option value="" disabled>Select</option>
</select>
<span ng-show="!editable">{{location.CityName}}</span>
</td>
<td><a class="btn btn-link" ng-click="editable = !editable">Edit</a></td>
</tr>
JS
$scope.recordLocation = function() {
$scope.locations.unshift({
CountryName: $scope.country.CountryName,
StateName: $scope.state.StateName,
CityName: $scope.city.CityName
});
$scope.city = {};
$scope.state = {};
$scope.country = [];
};
寻求有关如何解决此问题的帮助。
谢谢
【问题讨论】:
标签: angularjs angularjs-ng-repeat nested-forms angularjs-ng-model