如何在devextreme中过滤选择框
How to filter select-box in devextreme
我在筛选03个选择框、国家、州和城市时遇到了一些问题。如何使选择框嵌套?如何用这些数据进行筛选?
我的代码在script.js使用MySQL数据库:
var serviceFilterCountry = "http://localhost:8000/filtercountry";
var serviceFilterProvince = "http://localhost:8000/filterprovince";
var serviceFilterCity = "http://localhost:8000/filtercity";
$scope.countries = new DevExpress.data.DataSource(serviceFilterCountry);
$scope.provinces = new DevExpress.data.DataSource(serviceFilterProvince);
$scope.cities = new DevExpress.data.DataSource(serviceFilterCity);
//var dataSourceCity = new DevExpress.data.DataSource(serviceFilterCity);
//var dataSourceF = new DevExpress.data.DataSource(serviceFilter);
$scope.selectedProvince = null;
$scope.filterProvincesByCountry = function(e) {
var countryP = e.value;
$scope.provinces.filter("country", countryP);
$scope.provinces.load().done(function(result) {
$scope.selectedProvince = result.state;
});
};
$scope.selectedCity = null;
$scope.filterCitiesByProvince = function(e) {
var provinceC = e.value;
$scope.cities.filter("country", $scope.countries.select('country'));
$scope.cities.filter("state", provinceC);
$scope.cities.load().done(function(result) {
$scope.selectedCity = result.city;
});
};
要通过选择框值过滤数据,可以使用onValueChanged事件。例如,下面的代码显示了如何按国家id筛选城市:
JS:
$scope.countries = new DevExpress.data.DataSource({
store: [{id: 1, text: "USA"}, {id: 2, text: "Canada"}]
});
$scope.cities = new DevExpress.data.DataSource({
store: [{id: 1, countryId: 1, text: "NY"}, {id: 2, countryId: 2, text: "Toronto"}]
});
$scope.filterCitiesByCountry = function(e) {
var countryId = e.value;
$scope.cities.filter("countryId", countryId);
$scope.cities.load();
};
HTML: <div dx-select-box="{dataSource: countries, displayExpr: 'text', valueExpr: 'id', onValueChanged: filterCitiesByCountry}"></div>
<div dx-select-box="{dataSource: cities, displayExpr: 'text', valueExpr: 'id', bindingOptions: { value: 'selectedCity' } }"></div>
有关过滤器操作的更多信息请参阅此处。
我创建了一个小示例来实际演示这种方法- http://plnkr.co/edit/SR93AIRSp9TUuA5fYmpa
相关文章:
- Angular:使用选择列表选择过滤代码中的对象
- 使用PHP通过HTML表单选项选择器过滤MYSQL结果
- gulpuncss正在过滤我的javascript所需的选择器
- 如何根据角度中的复选框选择过滤结果
- 仅当选择特定的选择选项时,才使用JavaScript过滤数组
- d3在鼠标悬停上过滤数据之后从选择中提取值
- 转换UL->li inot为同位素过滤菜单选择的列表
- 通过标签选择过滤平行网格
- 过滤具有2个选择列表的元素
- 如何使用jQuery过滤/克隆选择框选项
- Dojo Dgrid - 可以在过滤选择上编辑
- 使用 jQuery 过滤选择框
- jquery 使用过滤功能过滤选择
- 如何在devextreme中过滤选择框
- angular中唯一的过滤选择列表,只返回数据集中的单个项
- Dojo,过滤选择,查询和排除字符串
- 根据data-*属性过滤选择选项
- 使用jquery过滤选择框内容
- 在点击提交后,停止过滤选择框的重置
- JQuery移动版中的多个可过滤选择菜单