gpt4 book ai didi

javascript - 通过传输更新kendo数据源

转载 作者:行者123 更新时间:2023-11-28 01:48:01 26 4
gpt4 key购买 nike

我正在尝试根据另一个下拉列表中选定的值 (cboSearchString1DDL.element[0].value) 设置远程数据 url。我继续学习 Kendo Web 控件,因此我不确定如何最有效地完成此任务。我尝试了几种途径,但在读取数据源时仍然收到错误。我正在尝试将其设置为 DDL1 的关闭。这就是我所处的位置,我知道这不是正确的方法:

// search string 1 DDL
var cboSearchString1DDL = $("#cboSearchString1DDL").kendoDropDownList({
autoBind: false,
optionLabel: " "
}).data("kendoDropDownList");

// search string 2 DDL
var cboSearchString2DDL = $("#cboSearchString2DDL").kendoDropDownList({
autoBind: false,
optionLabel: " "
}).data("kendoDropDownList");

// 1st DDL dataSource
var dataSourceTowns = new kendo.data.DataSource({
transport: {
read: {
url: _urlTowns,
dataType: "json",
}
},
schema: {
data: "Towns"
}
});

$("#cboSearchString1DDL").data("kendoDropDownList").wrapper.show();

// 1st DDL
var townsDDL = $("#cboSearchString1DDL").kendoDropDownList({
autoBind: false,
dataTextField: "Column1",
dataValueField: "Column1",
dataSource: dataSourceTowns,
close: function () {
alert(cboSearchString1DDL.element[0].value);
streetsDDL.enable(true);
streetsDDL.setDataSource(dataSourcestreetsDDL);
streetsDDL.refresh();
}
}).data("kendoDropDownList");

// show 2nd DDL
$("#cboSearchString2DDL").data("kendoDropDownList").wrapper.show();
cboSearchString2DDL.enable(false);

// 2nd DDL datasource
var dataSourcestreetsDDL = new kendo.data.DataSource({
transport: {
read: {
url: _urlSOESearchAddress + "townName=" + cboSearchString1DDL.element[0].value + "&f=",
dataType: "json",
},
},
schema: {
data: "StreetsinTown"
}
});

// 2nd DDL
var streetsDDL = $("#cboSearchString2DDL").kendoDropDownList({
autoBind: false,
dataTextField: "Street",
dataValueField: "Street",
requestStart: function (e) {
console.log("request started");
},
requestEnd: function (e) {
var response = e.response;
var type = e.type;
console.log(type);
console.log(response.length);
}
}).data("kendoDropDownList");

提前致谢!

最佳答案

请记住,url 可以是一个以字符串形式返回 URL 的函数。因此,如果更容易编码,您也可以执行以下操作:

var dataSourcestreetsDDL = new kendo.data.DataSource({
transport: {
read: {
url: function () {
var searchAddress = ...;
var searchString = ...;
return searchAddress + "townName=" + searchString + "&f=";
}
...

每当数据源需要读取数据时,就会调用该函数。这可能比下拉菜单关闭时更改内容更容易。

关于javascript - 通过传输更新kendo数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20056281/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com