我有级联下拉列表,当尝试定义初始值(也在级联下)而不是调用具有父选定值的 ajax 控制器方法时,它传递了空白值。
我有类似的要求,我可以保存我最后的搜索值并将其存储在 int 数据库中,再次进入该屏幕后,默认情况下将选择值。
一切都在 Javascript 中意味着存储值/检索并应用于控件:
我的级联下拉代码:
<div style="width: 400px; clear: both; float: left; position: relative; display: table-cell;">
<ul style="width: 450px; clear: both; float: none;">
<li>
<div class="editor-row">
<div class="editor-label-short">Home Country</div>
<div class="editor-field">
@(Html.Kendo().DropDownList()
.Name("HOME_COUNTRY_ID")
.HtmlAttributes(new { style = "width:200px" })
.OptionLabel("Select Home Country")
.DataTextField("Text")
.DataValueField("Value")
.DataSource(source => source.Read(read => read.Action("GetCountryJSON", "Employee")))
)
</div>
</div>
</li>
<li>
<div class="editor-row">
<div class="editor-label-short">Home City</div>
<div class="editor-field">
@(Html.Kendo().DropDownList()
.Name("HOME_CITY_ID")
.HtmlAttributes(new { style = "width:200px" })
.OptionLabel("Select Home City")
.DataTextField("Text")
.DataValueField("Value")
.DataSource(source => source.Read(read => read.Action("GetCityByCountryJSON", "Employee")
.Data("getCountryId"))
.ServerFiltering(true))
.AutoBind(false)
.CascadeFrom("HOME_COUNTRY_ID")
)
</div>
</div>
</li>
</ul>
</div>
在页面加载中分配值的 Javacript 代码意味着在 Dom 准备好之后:
function applyvaluetoControls() {
setdefaultvaluestoControls();
$.each(activeLayout.controls, function(index) {
$.each(options.emementArray, function(innerindex) {
if (options.emementArray[innerindex].attr("id") === activeLayout.controls[index]["id"]) {
if ((options.emementArray[innerindex]).is(':checkbox')) {
options.emementArray[innerindex].prop('checked', activeLayout.controls[index]["value"]);
} else {
if (options.emementArray[innerindex].attr("data-role") !== undefined && options.emementArray[innerindex].attr("data-role") === "dropdownlist") {
// console.log(options.emementArray[innerindex].data('kendoDropDownList'));
if (options.emementArray[innerindex].data('kendoDropDownList').options.cascadeFrom !== "") {
console.log($("#" + options.emementArray[innerindex].data('kendoDropDownList').options.cascadeFrom).val());
options.emementArray[innerindex].data('kendoDropDownList').dataSource.read({ CompanyId: $("#" + options.emementArray[innerindex].data('kendoDropDownList').options.cascadeFrom).val() });
options.emementArray[innerindex].data('kendoDropDownList').value(activeLayout.controls[index]["value"]);
} else {
options.emementArray[innerindex].data('kendoDropDownList').enable();
options.emementArray[innerindex].data('kendoDropDownList').value(activeLayout.controls[index]["value"]);
}
console.log(activeLayout.controls[index]["id"]);
console.log(activeLayout.controls[index]["value"]);
} else {
options.emementArray[innerindex].val(activeLayout.controls[index]["value"]);
}
}
}
});
});
}
控制台日志:
HOME_COUNTRY_ID // 父控件 ID
第322章
// Blank value when I am trying to read the value Parent Control (Country)
City : // 父级触发智利,但具有空白值 HOME_CITY_ID // 子级 342 // 值
City : 322 // 退出循环后,它再次使用 Parent 选择值调用 Child
它正在消除孩子的初始选定值。
任何帮助将不胜感激!