<div ng-controller="AjaxCtrl">
      <h1>AJAX - Oriented</h1>
    <div>
        Country: 
        <select >
          <option value=''>Select</option>
        </select>
    </div>
    <div>
        City: <select ><option value=''>Select</option></select>
    </div>
    <div>
        Suburb: <select ><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 >
          <option value=''>Select</option>
        </select>
    </div>
    <div>
        City: <select ><option value=''>Select</option></select>
    </div>
    <div>
        Suburb: <select ><option value=''>Select</option></select>        
    </div>
  </div>
angularjs三级联动

js

angularjs三级联动
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']
        }
    };
}

相关文章:

  • 2021-06-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-09
相关资源
相似解决方案