欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

AngularJS实现的select二级联动下拉菜单功能示例

程序员文章站 2022-06-25 13:37:19
本文实例讲述了angularjs实现的select二级联动下拉菜单功能。分享给大家供大家参考,具体如下:

本文实例讲述了angularjs实现的select二级联动下拉菜单功能。分享给大家供大家参考,具体如下:

<!doctype html>
<html ng-app>
<head lang="en">
  <meta charset="utf-8">
  <title></title>
</head>
<script src="../script/angular.js"></script>
<body ng-controller="controller">
<div>所属分类:
  <select ng-model="selected1" ng-options="m.rolename for m in classification1" ng-change="changeclassification(selected1)">
    <option value="">-- 请选择 --</option>
  </select>
  <select ng-model="selected2" ng-options="m.rolename for m in classification2">
    <option value="">-- 请选择 --</option>
  </select>
</div>
</body>
<script>
  var contantcrolelist = [
    { "rolename" : "软件开发", "roleid" : "role1", "children" : [
      { "rolename" : "软件aaa", "roleid" : "role11", "children" : [] },
      { "rolename" : "软件bbb", "roleid" : "role12", "children" : []},
      { "rolename" : "软件ccc", "roleid" : "role12", "children" : []},
      { "rolename" : "软件ddd", "roleid" : "role12", "children" : []},
      { "rolename" : "软件eee", "roleid" : "role12", "children" : []},
      { "rolename" : "软件fff", "roleid" : "role12", "children" : []}
    ]},
    { "rolename" : "硬件开发", "roleid" : "role2", "children" : [
      { "rolename" : "硬件aaa", "roleid" : "role21", "children" : [] },
      { "rolename" : "硬件bbb", "roleid" : "role22", "children" : []},
      { "rolename" : "硬件ccc", "roleid" : "role23", "children" : []},
      { "rolename" : "硬件ddd", "roleid" : "role24", "children" : []},
      { "rolename" : "硬件eee", "roleid" : "role25", "children" : []},
      { "rolename" : "硬件fff", "roleid" : "role26", "children" : []}
    ]},
    { "rolename" : "嵌入式开发", "roleid" : "role3", "children" : [
      { "rolename" : "嵌入式aaa", "roleid" : "role31", "children" : [] },
      { "rolename" : "嵌入式bbb", "roleid" : "role32", "children" : []},
      { "rolename" : "嵌入式ccc", "roleid" : "role33", "children" : []},
      { "rolename" : "嵌入式ddd", "roleid" : "role34", "children" : []},
      { "rolename" : "嵌入式eee", "roleid" : "role35", "children" : []},
      { "rolename" : "嵌入式fff", "roleid" : "role36", "children" : []}
    ]}
  ];
  function controller($scope) {
    $scope.classification1 = contantcrolelist;
    $scope.changeclassification = function (selected1) {
      $scope.classification2 = selected1.children;
    };
  }
</script>
</html>

更多关于angularjs相关内容感兴趣的读者可查看本站专题:《angularjs指令操作技巧总结》、《angularjs入门与进阶教程》及《angularjs mvc架构总结

希望本文所述对大家angularjs程序设计有所帮助。