答案 0 :(得分:1)
您可以在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;
};
<强> FULL EXAMPLE 强>
可以对其他$scope.samples
键进行过滤的类似功能