zoukankan      html  css  js  c++  java
  • angularjs三级联动

    <div ng-controller="AjaxCtrl">
          <h1>AJAX - Oriented</h1>
        <div>
            Country: 
            <select id="country" ng-model="country" ng-options="country for country in countries">
              <option value=''>Select</option>
            </select>
        </div>
        <div>
            City: <select id="city" ng-disabled="!cities" ng-model="city" ng-options="city for city in cities"><option value=''>Select</option></select>
        </div>
        <div>
            Suburb: <select id="suburb" ng-disabled="!suburbs" ng-model="suburb" ng-options="suburb for suburb in suburbs"><option value=''>Select</option></select>        
        </div>
    </div>
      <div ng-controller="StaticCtrl">
          <h1>Static - Oriented</h1>
          <p>This approach may be better when you have the entire dataset</p>
        <div>
            Country: 
            <select id="country" ng-model="cities" ng-options="country for (country, cities) in countries">
              <option value=''>Select</option>
            </select>
        </div>
        <div>
            City: <select id="city" ng-disabled="!cities" ng-model="suburbs" ng-options="city for (city, suburbs) in cities"><option value=''>Select</option></select>
        </div>
        <div>
            Suburb: <select id="suburb" ng-disabled="!suburbs" ng-model="suburb" ng-options="suburb for suburb in suburbs"><option value=''>Select</option></select>        
        </div>
      </div>
    复制代码

    js

    复制代码
    function AjaxCtrl($scope) {
        $scope.countries = ['usa', 'canada', 'mexico', 'france'];
        $scope.$watch('country', function(newVal) {
            if (newVal) $scope.cities = ['Los Angeles', 'San Francisco'];
        });
        $scope.$watch('city', function(newVal) {
            if (newVal) $scope.suburbs = ['SOMA', 'Richmond', 'Sunset'];
        });
    }
    
    function StaticCtrl($scope) {
        $scope.countries = {
            'usa': {
                'San Francisco': ['SOMA', 'Richmond', 'Sunset'],
                'Los Angeles': ['Burbank', 'Hollywood']
            },
            'canada': {
                'People dont live here': ['igloo', 'cave']
            }
        };
    }
  • 相关阅读:
    开源一些C#不常用知识(附上DEMO)
    开源:C# 代码自动生成工具,支持站点前后台
    Xposed 集成 Android 6.0.1环境中,总结
    Android 视频通信,低延时解决方案
    Android studio,第一个生成,调用成功的jni(说多了都是泪)
    C#之文件缓存
    JavaScript 基本常识
    排序算法
    LeetCode:字符串转换整数 (atoi)
    LeetCode:判断回文数
  • 原文地址:https://www.cnblogs.com/susanws/p/5476735.html
Copyright © 2011-2022 走看看