我有两个选择控件。基于一个选择控件,第二个选择控件应该填充,就像国家选择状态一样,将填入第二个选择控件。
我的代码就像 -
<select ng-model="parentModel" id="ddlState">
<option value="mp"> mp </option>
<option value="mh"> mh </option>
</select>
<select ng-model="childModel" id="ddlcity" ng-options = "a as a for a in $scope.coll[parentModel]">
</select>
和脚本是 -
<script>
var arr= new Array();
arr["mp"] = ['map1','map2'];
arr["mh"] = ['mh11','mh2'];
myapp = angular.module("myapp", []);
myapp.controller("MyController", function ($scope) {
$scope.parentModel = "mh";
//$scope.childModel="pune";
$scope.coll=arr;
});
</script>
提前致谢...
答案 0 :(得分:1)
你有正确的想法 - 虽然有一些改变:
JavaScript没有关联数组,因此请使用对象:
$scope.arr = {};
$scope.arr.mp = ["map1", "map2"];
$scope.arr.mh = ["mh11", "mh2"];
无需在$scope
ng-options
ng-options = "a as a for a in arr[parentModel]"
不确定$scope.coll
是什么意思......但在您的情况下不需要依赖select
。