原理:
1.ng-options中val.id as val.name for val in cascading 將id的值賦給 mg-modelone
2.在通過ng-change傳給函數
3.當一級下拉菜單的值改變后,執行函數,去后台請求二級下拉菜單的數據,並加載
angularjs代碼:
app.controller('addmultiple_scontroller', function($scope, $http) {
//常量
$scope.postCfg = postCfg;
$scope.modelone = "";
$scope.modeltwo = "";
$http.post("./getAllExamNameByTid.action").success(function(res) {
$scope.cascading = res;
});
$scope.changeone = function(val) {
if(null != val){
$http.post("./getAllExamClassifyByEnid.action",{
"en_id": val
},$scope.postCfg).success(function(res) {
$scope.cascadingtwo = res;
});
}
}
});
html代碼:
<p> <label> <span>所屬題庫:</span> <select ng-model="modelone" ng-options="val.id as val.name for val in cascading" ng-change="changeone(modelone)"> <option value="">--請選擇--</option> </select> </label> <label> <select name="" ng-model="modeltwo" ng-options="val.id as val.name for val in cascadingtwo"> <option value="">--請選擇--</option> </select> </label> </p>
