所以我目前使用 2 个下拉列表,其中第二个应该根据从第一个中选择的项目从服务器获取项目,问题是这仅在我第一次单击子下拉列表时有效,这意味着如果我更改父列表项孩子仍然会显示以前的项目。
这是一些代码:
kendofi=function (index){
//kendofi select boxes
$("#dynamicFormLinha"+index).kendoDropDownList({
name:"formularios",
optionLabel: "Formulario",
dataTextField: "name",
dataValueField: "id",
dataSource: {
type: "json",
serverFiltering: true,
transport: {
read: "${pageContext.request.contextPath}" + "/newlayout/mySearchesDynForms.do"
},
schema: {
model: {
fields: {
id: { type: "number" },
name: { type: "string" }
}
}
}
}
}).data("kendoDropDownList");
$("#campoFormLinha"+index).kendoDropDownList({
autoBind:false,
name:"campos",
optionLabel: "Campo",
dataTextField: "name",
dataValueField: "id",
dataSource: {
type: "json",
serverFiltering:true,
transport: {
read:{
url:"${pageContext.request.contextPath}" + "/newlayout/mySearchesFormFieds.do",
data:function(){
return {formId: $("#dynamicFormLinha"+index).val()
};
}
}
}
},
cascadeFrom: "dynamicFormLinha1",
schema: {
model: {
fields: {
id: { type: "number" },
name: { type: "string" }
}
}
}
}).data("kendoDropDownList");
这是每个下拉列表的 java spring 控制器类方法:
@RequestMapping(method = RequestMethod.GET, value="/newlayout/mySearchesDynForms")
public @ResponseBody
DynamicFormTemplateDPO[] getForms(){
return dynamicFormService.getAllActiveFormTemplatesForPresentation();
}
@RequestMapping(method = RequestMethod.GET, value="/newlayout/mySearchesFormFieds")
public @ResponseBody
DynamicFieldTemplateDPO[] getFormFields(@RequestParam long formId){
return dynamicFormService.getFormFields(formId);
}
这些都返回 json 数据,父子返回:
[{"id":1,"name":"drcie"},{"id":2,"name":"edp"},{"id":3,"name":"pt"}]
然后将选择的 id 用作 getFormFields 方法中的 formId 参数,该方法返回如下内容:
[{"id":1,"name":"Nome","type":"STRING"},{"id":2,"name":"Morada","type":"STRING"},{"id":3,"name":"Contribuinte","type":"STRING"},{"id":4,"name":"Multibanco","type":"STRING"}]
这里的 kendofi 方法是因为这些小部件位于表格内,您可以在维护小部件功能的同时添加新的表格行。