【发布时间】:2017-03-27 21:00:30
【问题描述】:
【问题讨论】:
-
您能否详细说明您的问题是什么?谢谢。
-
你能解释一下你想要达到的目标吗?
-
@Nishant123 正如您在小提琴中看到的,我需要根据相关国家/地区过滤城市。这意味着当我选择美国时,只会出现相关城市。请看一下小提琴。
【问题讨论】:
您可以在ng-change 上添加一个函数,该函数将返回所选国家/地区的所有城市
$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;
};
类似的功能可以用于过滤其他$scope.samples键
【讨论】: