我非常喜欢AngularJS(1.6),我需要从选择的选项中过滤一些结果。
我必须从州中过滤城市,在此之前我做得很好。但是我需要过滤并在列表中显示这个城市的商店。有人知道怎么做吗?
我的代码:
<!DOCTYPE html>
<html data-ng-app="myApp">
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.7/angular.min.js"></script>
</head>
<body data-ng-controller="testController">
<select id="state" ng-model="stateSrc" ng-options="state for (state, city) in states" ng-change="GetSelectedState()">
<option value=''>State</option>
</select>
<select id="city" ng-model="citySrc" ng-options="city for (city,store) in stateSrc" ng-change="GetSelectedCity()" ng-disabled="!stateSrc">
<option value=''>City</option>
</select>
<select id="city" ng-model="store" ng-options="store for store in citySrc" ng-disabled="!stateSrc || !citySrc">
<option value=''>Store</option>
</select>
<script>
angular
.module('myApp', [])
.run(function($rootScope) {
$rootScope.title = 'myTest Page';
})
.controller('testController', ['$scope', function($scope) {
$scope.states = {
'STATE_1': {
'City_1': ['Store_1', 'Store_2'],
'City_2': ['Store_3', 'Store_4']
},
'STATE-2': {
'City_3': ['Store_1', 'Store_2'],
'City_4': ['Store_3', 'Store_4']
}
};
$scope.GetSelectedState = function() {
$scope.strState = $scope.stateSrc;
};
$scope.GetSelectedCity = function() {
$scope.strCity = $scope.citySrc;
};
}
])
</script>
</body>
</html>非常感谢!
发布于 2018-02-07 23:29:10
如果你发布了你的数据源的样子,这将会非常有帮助。假设citySrc有包含存储数组的对象,当您调用GetSelectedCity()时,我会在控制器中设置一个selectedCity,然后:
<ul>
<li ng-repeat="store in selectedCity.store">{{store}}</li>
</ul>这将为您的selectedCity对象中的每个商店创建列表项。
https://stackoverflow.com/questions/48667323
复制相似问题