Kendo ui 剑道UI级联下拉列表初始值未设置

Kendo ui 剑道UI级联下拉列表初始值未设置,kendo-ui,kendo-dropdown,Kendo Ui,Kendo Dropdown,我有cascade下拉列表,当尝试定义初始值(也在cascade下)时,用父选择值调用ajax控制器方法,它会传递空白值 我有这样的要求,我可以保存我最后的搜索值并将其存储在数据库中,再次进入该屏幕后,默认情况下将选择值 一切都在Javascript中意味着存储值/检索并应用于控件: 我的级联下拉代码: <div style="width: 400px; clear: both; float: left; position: relative; display: table-cell;"&

我有cascade下拉列表,当尝试定义初始值(也在cascade下)时,用父选择值调用ajax控制器方法,它会传递空白值

我有这样的要求,我可以保存我最后的搜索值并将其存储在数据库中,再次进入该屏幕后,默认情况下将选择值

一切都在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>
 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"]);
                        }

                    }
                }
            });
        });
    }
控制台日志:

<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>
 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"]);
                        }

                    }
                }
            });
        });
    }
母国ID//父控件ID

322//它将值设置为Parent

     // Blank value when I am trying to read the value Parent Control (Country)
City://但值为空 家乡城市ID//孩子 342//价值

City:322//退出循环后,它再次使用父选择值调用子对象

它抹去了孩子最初的选择值


我们将非常感谢您的帮助

儿童在您的儿童下拉列表中使用示例中的这些属性,您将指示下拉列表:

.AutoBind(false) //<--Don't do any data retrieval until asked or clicked
.OptionLabel("Select Home City") //<--If the value is null display this and value will be "" 
.CascadeFrom("HOME_COUNTRY_ID") //<--Get my values using the DataValueField from this control and refresh when it changes
子下拉配置

.Name("ddlParent")
.OptionLabel((@Model.ForceParentSelect) ? "" : "All Parents")
.Value(Model.ParentID.HasValue ? Model.ParentID.Value.ToString() : "")
.DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("GetParents", "Parent");
        });
    })
<script>
    function filterChild{ return { ParentID: $("#ddlParent").val() }; }
</script>

.Name("ddlChild")
.OptionLabel((@Model.ForceChildSelect) ? "" : "All Childs")
.Value(Model.ChildID.HasValue ? Model.ChildID.Value.ToString() : "")
.AutoBind(Model.ParentID.HasValue)
.CascadeFrom(Model.ParentID.HasValue ? "" : "ddlParent")
.DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("GetChildren", "Child")
                .Data("filterChild");
        })            
    })

函数filterChild{return{ParentID:$(“#ddlParent”).val()};}
.姓名(“子女”)
.OptionLabel((@Model.ForceChildSelect)?“”:“所有儿童”)
.Value(Model.ChildID.HasValue?Model.ChildID.Value.ToString():“”)
.AutoBind(Model.ParentID.HasValue)
.CascadeFrom(Model.ParentID.HasValue?”:“ddlParent”)
.DataSource(source=>
{
source.Read(Read=>
{
阅读.操作(“获取儿童”、“儿童”)
.数据(“过滤儿童”);
})            
})

感谢您的回复,但在我的例子中,我有这个ParentId和值来自Javascript并使用scope进行设置。场景是,我有高级搜索字段,在字段中输入的内容,我存储这些值。例如:如果字段中有名字和姓氏值,那么我将只存储名字和姓氏,而不存储国家和城市。那样的话我怎么能触发呢?