Multi select 基于另一个 multi select

Multi select based on another multi select

我需要在这些多选中根据国家过滤城市。 我使用 ui-select 进行多选,感谢@tanmay。

请看看这个fiddle。

Fiddle

您可以在 ng-change 上添加一个函数,该函数将 return 所选国家/地区的所有城市

 $scope.getCityList=function(){

      var sampletemp = []; //temp array to hold filtered values
      $scope.selected.country.forEach(function(country) {
      //bjectFromArrayFilter --> A filter function that will do the filtering
      var temp =    objectFromArrayFilter($scope.samples,'country',country);
      sampletemp = sampletemp.concat(temp);
      //Filter duplicate city names
      $scope.uniquecity = $filter('unique')(sampletemp, 'city');
      //Reset all the already selected values
      $scope.selected.city= [];

      $scope.city = $scope.uniquecity.map(function(item) {
      return item.city
        })
    }

过滤功能。

您也可以使用此功能进行自定义过滤。只需传递对象数组,过滤键和值即可匹配

var objectFromArrayFilter=function(arrayOptions, key, value) {
    var filterResult = arrayOptions.filter(function(val) {
            return val[key] === value;
    });
    return filterResult;
};

FULL EXAMPLE

可以在其他 $scope.samples 键上进行类似的过滤