qq_33661044
_抱歉打扰了
2017-09-28 09:44

angularjs 实现省市级联菜单的默认值显示问题

10
  • angular.js
  • 级联菜单回显

首先是二级菜单级联

 <div class="form-group">
                            <label class="col-sm-2 control-label">所在省份</label>
                            <div class="col-sm-10">
                               ** <select class="form-control"
                                        ng-model="model.school.province" ng-options="s.name  for s in list" ng-change=**"change()">
                                    <option value="">请选择省份</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group"  >
                            <label class="col-sm-2 control-label" >所在城市</label>
                            <div class="col-sm-10">
                                **<select class="form-control"
                                        ng-model="model.school.city" ng-options="sh.name for sh in model.school.province.child">**
                                    <option value="">请选择所在城市</option>
                                </select>
                            </div>
                        </div>

然后controller

  //初始化地区信息
        $scope.list = [];
        $http.get('./config/json/area.json').success(function (data) {
            $scope.list = data;
            console.log(data);
        });

接着是json数据、数据太长删掉一部分

 [
  {
    "name": "北京",
    "child": [
      {"name":"东城区"},
      {"name":"西城区"},
      {"name":"崇文区"},
      {"name":"宣武区"},
      {"name":"朝阳区"},
      {"name":"丰台区"},
      {"name":"石景山区"},
      {"name":"海淀区"},
      {"name":"门头沟区"},
      {"name":"房山区"},
      {"name":"通州区"},
      {"name":"顺义区"},
      {"name":"昌平区"},
      {"name":"大兴区"},
      {"name":"平谷区"},
      {"name":"怀柔区"},
      {"name":"密云县"},
      {"name":"延庆县"}
    ]
  },
  {
    "name": "天津",
    "child": [
      {"name":"和平区"},
      {"name":"河东区"},
      {"name":"河西区"},
      {"name":"南开区"},
      {"name":"河北区"},
      {"name":"红桥区"},
      {"name":"塘沽区"},
      {"name":"汉沽区"},
      {"name":"大港区"},
      {"name":"东丽区"},
      {"name":"西青区"},
      {"name":"津南区"},
      {"name":"北辰区"},
      {"name":"武清区"},
      {"name":"宝坻区"},
      {"name":"宁河县"},
      {"name":"静海县"},
      {"name":"蓟  县"}
    ]
  },
  {
    "name": "安徽",
    "child": [
      {
        "name": "合肥"
      },
      {
        "name": "芜湖"
      },
      {
        "name": "蚌埠"
      },
      {
        "name": "淮南"
      },
      {
        "name": "马鞍山"
      },
      {
        "name": "淮北"
      },
      {
        "name": "铜陵"
      },
      {
        "name": "安庆"
      },
      {
        "name": "黄山"
      },
      {
        "name": "滁州"
      },
      {
        "name": "阜阳"
      },
      {
        "name": "宿州"
      },
      {
        "name": "巢湖"
      },
      {
        "name": "六安"
      },
      {
        "name": "亳州"
      },
      {
        "name": "池州"
      },
      {
        "name": "宣城"
      },
      {
        "name": "其他"
      }
    ]
  }
]

现在的问题是回显数据的时候,如何回显。就是我给省份和城市一个默认值
比如陕西、西安。我在查看的时候select默认值要选中。
有没有大神解答

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换