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>

 
                    
            
                

相关文章:

  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2022-01-27
  • 2021-09-26
  • 2021-12-20
猜你喜欢
  • 2022-12-23
  • 2021-06-14
  • 2021-09-17
  • 2021-11-22
  • 2021-07-17
  • 2022-01-17
相关资源
相似解决方案