选择级联下拉列表的默认值

时间:2014-04-14 03:43:44

标签: javascript jquery asp.net-mvc-3 kendo-ui

我只想问一下如何在第一个下拉列表的更改中选择第二个/级联下拉列表的默认值? 我想在更改位置下拉列表时选择[Please Select Location]   我试过这种方法,但错误说select is undefined

  var dropdownlist = $("#ddlLocation").data("kendoDropDownList");
                dropdownlist.select(function (dataItem) {
                    return dataItem.symbol === "[Please Select Location]";
                });

这是我的一组代码:

var userId = $("#hiddenUser").val();
    $("#PositionInputs").kendoDropDownList({
        dataTextField: "Name",
        dataValueField: "ID",
        index: 0,
        autoBind: false,
        change: function () {
            var value = this.value();
            var dataItem1 = this.dataItem(this.select());
            if (value) {
                var dropdownlist = $("#ddlLocation").data("kendoDropDownList");
                dropdownlist.select(function (dataItem) {
                    return dataItem.symbol === "[Please Select Location]";
                });

            }
        },
        optionLabel: "[Please Select Position]",
        template: '<h5>${ data.Name }</h5>',
        dataSource: {
            transport: {
                read: {
                    url: '/Profile/LoadDropdownList?userId=' + userId,
                    dataType: "json",
                    type: "POST"

                }
            }
        }

    });


    //kendo dropdown
    $("#ddlPosition").kendoDropDownList({
        dataTextField: "Name",
        dataValueField: "ID",
        autoBind: false,
          optionLabel: {
              Name: "[Please Select Position]",
              ID: "0"
    },
        //   define custom template
        template:
                                   '<h5>${ data.Name }</h5>',
        dataSource: {
            transport: {
                read: {
                    url: '/Profile/LoadDropdownList?userId=' + userId,
                    dataType: "json",
                    type: "POST"
                }
            }
        }
    });



    //kendo dropdown
    $("#ddlLocation").kendoDropDownList({
        dataTextField: "Address",
        dataValueField: "Id",
        autoBind: false,
        optionLabel: "[Please Select Position]",
        //   define custom template
        template: '<h5>${ data.Address }</h5>',
        dataSource: {
            transport: {
                read: {
                    url: '/Profile/LoadLocationDropdownList?userId=' + userId,
                    dataType: "json",
                    type: "POST"
                }
            }
        }

    });




    $("#LocationInputs").kendoDropDownList({
        dataTextField: "Address",
        dataValueField: "Id",
        //                    index: 0,
        autoBind: false,
        cascadeFrom: "PositionInputs",
        optionLabel: {
            Address: "[Please Select Position]",
            Id: "0"
        },
        template: '<h5>${ data.Address }</h5>',
        dataSource: {
            transport: {
                read: {
                    url: '/Profile/LoadLocationDropdownList?userId=' + userId,
                    dataType: "json",
                    type: "POST"
                }
            }
        }
    });

1 个答案:

答案 0 :(得分:1)

您使用的代码会选择项目,如果其文本等于&#34; [请选择位置]&#34;但此处定义的位置下拉菜单设置为&#34; [请选择位置]&#34;。

如果进行此更改不起作用,您可以尝试设置索引(假设占位符的索引为0):

var ddl = $("#someId").data("kendoDropDownList");
ddl.select(0)