angularjs之級聯菜單


原理:

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>
 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM