基于另一个多重选择的多重选择 [英] Multi select based on another multi select

查看:62
本文介绍了基于另一个多重选择的多重选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to filter city based on the country in these multi-selects. I used ui-select for multi-selects, Thanks to @tanmay.

请看看这个小提琴.

小提琴

推荐答案

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

You can add a function on ng-change that will return all the cities for the selected country

 $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
        })
    }

过滤功能.

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

You can also use this function to perform custom filtering. Just pass the array of objects, filtering key and value to match

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

完整示例

FULL EXAMPLE

可以使用类似的功能来过滤其他 $ scope.samples

Similar function can be made for filtering on other $scope.samples keys

这篇关于基于另一个多重选择的多重选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆