在Spring MVC环境中使用dijit.filteringselect
我试图编码两个filteringselects,它们都应该根据输入到任何表单中的数据进行更改在Spring MVC环境中使用dijit.filteringselect,spring,dojo,Spring,Dojo,我试图编码两个filteringselects,它们都应该根据输入到任何表单中的数据进行更改 @ResponseBody @RequestMapping("/ajax/country/{country}") public List<City> clientSelection(@PathVariable("country") String country ) { log.info("Country = {} ",country);
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
所以输入fs1的数据应该会触发fs2的变化。
输入fs2的数据应触发fs1的更改
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
我在spring环境中,这意味着dojo代码在jsp文件中,过滤选择字段通过服务器端的控制器类填充,使用@ModelAttribute注释使数据作为jsp文件中的变量可用
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
我在Java端有关系数据,所以它可以通过控制器获得
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
这就是目前让我困惑的地方
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
这个问题也可以理解为:我如何使用输入参数调用一个方法,该参数保存编辑的filteringselect中可用的数据 我建议我们分两个增量部分来解决这个问题:
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
过滤器选择的onChange
事件工作
filteringselect
,其中第二个由onChange
事件处理程序依赖于第一个
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
你能试着运行一下吗?如果你能让它工作,请告诉我
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
一旦我们得到第一个过滤器select
触发第二个过滤器,我将编辑添加关于如何将它们转换为使用服务器端数据存储的解释
<html>
<head>
<title>Test File</title>
<link type="text/css" rel="stylesheet" href="dijit/themes/tundra/tundra.css"/>
</head>
<body class="tundra">
<label for="state">State:</label>
<input id="state">
<label for="city">City:</label>
<input id="city">
<script type="text/javascript" src="dojo/dojo.js"
djConfig="isDebug: true, parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojo.data.ItemFileReadStore");
dojo.addOnLoad(function() {
var cityJson = {
label: 'name',
items: [{ name: 'Albany', state: 'NY' },
{ name: 'New York City', state: 'NY' },
{ name: 'Buffalo', state: 'NY' },
{ name: 'Austin', state: 'TX' },
{ name: 'Houston', state: 'TX' }]
};
var stateJson = {
identifier: 'abbreviation',
label: 'name',
items: [ { name: 'New York', abbreviation: 'NY' },
{ name: 'Texas', abbreviation: 'TX' } ]
};
new dijit.form.ComboBox({
store: new dojo.data.ItemFileReadStore({
data: cityJson
}),
autoComplete: true,
query: {
state: "*"
},
style: "width: 150px;",
required: true,
id: "city",
onChange: function(city) {
dijit.byId('state').attr('value', (dijit.byId('city').item || {
state: ''
}).state);
}
},
"city");
new dijit.form.FilteringSelect({
store: new dojo.data.ItemFileReadStore({
data: stateJson
}),
autoComplete: true,
style: "width: 150px;",
id: "state",
onChange: function(state) {
dijit.byId('city').query.state = state || "*";
}
},
"state");
});
</script>
</body>
</html>
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
测试文件
声明:
城市:
require(“dijit.form.FilteringSelect”);
require(“dojo.data.ItemFileReadStore”);
dojo.addOnLoad(函数(){
var cityJson={
标签:“名称”,
项目:[{name:'Albany',state:'NY'},
{名称:'纽约市',州:'纽约'},
{名称:'Buffalo',州:'NY'},
{名称:'Austin',州:'TX'},
{名称:'休斯顿',州:'德克萨斯'}]
};
var stateJson={
标识符:'缩写',
标签:“名称”,
项目:[{名称:'纽约',缩写:'纽约'},
{名称:'Texas',缩写:'TX'}]
};
新dijit.form.ComboBox({
存储:新的dojo.data.ItemFileReadStore({
数据:cityJson
}),
自动完成:正确,
查询:{
国家:“*”
},
样式:“宽度:150px;”,
要求:正确,
id:“城市”,
变更:功能(城市){
dijit.byId('state').attr('value'),(dijit.byId('city')。项| |{
状态:“”
})(国家);
}
},
“城市”);
新dijit.form.FilteringSelect({
存储:新的dojo.data.ItemFileReadStore({
数据:stateJson
}),
自动完成:正确,
样式:“宽度:150px;”,
id:“国家”,
onChange:函数(状态){
dijit.byId('city').query.state=state | |“*”;
}
},
“国家”);
});
在jsp的命名空间中:
xmlns:springform="http://www.springframework.org/tags/form"
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
样本表格:
<springform:form action="#" >
<label for="country">Country:</label>
<springform:select id="country" path="country" items="${countryList}" itemLabel="country" itemValue="id"/>
<div id="citySelectDiv"></div>
</springform:form>
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
国家:
javascript代码:
<script type="text/javascript">
<![CDATA[
dojo.require("dojo.parser");
dojo.require("dojo.data.ItemFileReadStore");
function countryChanged(dataFromServer){
//convert json to dojo filteringSelect options
var options = {
identifier: 'id',
label: 'city',
items: dataFromServer
};
var cityStore =new dojo.data.ItemFileReadStore({data : options});
// create Select widget, populating its options from the store
if (!dijit.byId("citySelectDiv")) {
//create city selction combo
new dijit.form.FilteringSelect({
name: "citySelectDiv",
store: cityStore,
searchAttr : "city",
}, "citySelectDiv");
}else{
//if already created the combo before
dijit.byId('citySelectDiv').set('value',null);
dijit.byId('citySelectDiv').store = cityStore;
}
}
Spring.addDecoration(new Spring.ElementDecoration({
elementId : "country",
widgetType : "dijit.form.FilteringSelect",
widgetAttrs : {
promptMessage: "Select a Country",
required : true,
onChange : function(){
var xhrArgs = {
url: "ajax/country/" +dijit.byId('country').get('value'),
handleAs: 'json',
load: function(dataFromServer) {
countryChanged(dataFromServer);
}
};
//make the ajax call
dojo.xhrGet(xhrArgs);
}
}
}));
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
样本控制器方法:
@ResponseBody
@RequestMapping("/ajax/country/{country}")
public List<City> clientSelection(@PathVariable("country") String country ) {
log.info("Country = {} ",country);
return cityService.findCitiesByCountry(country);
}
@ResponseBody
@请求映射(“/ajax/country/{country}”)
公共列表客户端选择(@PathVariable(“国家”)字符串国家){
log.info(“Country={}”,Country);
返回cityService.findCitiesByCountry(国家/地区);
}