我需要帮助
三个选定下拉菜单
当第二个选择菜单打开后的一个选择菜单值,以及当第三个选择菜单打开后的第二个选择菜单值在angularjs中打开时,我已经创建了Fiddle,
但我有一个问题,我有数据在数组中,每当我传递数据时,时间显示在字符串中。
注释中的小提琴链接。。

最佳答案

请试试这个小提琴,它会帮你的。

https://jsfiddle.net/annavester/Zd6uX/

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']
        }
    };
}

  <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>

试试看。

关于html - 如何在angularjs中三个选择菜单句柄,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35793282/

10-12 15:19