简体   繁体   English

剑道下拉默认选择

[英]Kendo dropdown default selection

I've a Kendo dropdown like below: 我有一个剑道下拉菜单,如下所示:

KM.ddlModel.bind("loaded", function () {
        $("#dvDDL").kendoDropDownList({
            dataTextField: "Text",
            dataValueField: "Value",
            dataSource: KM.ddlModel.cmg
        });

Now I would like to set the selected value based on a condition. 现在,我想根据条件设置选定的值。 How can I do it? 我该怎么做?

There are many ways you can do this. 您可以通过多种方式执行此操作。

At its simplest (a true or false condition), you can do the following: 最简单的(正确或错误的条件),您可以执行以下操作:

KM.ddlModel.bind("loaded", function () {
        $("#dvDDL").kendoDropDownList({
            dataTextField: "Text",
            dataValueField: "Value",
            dataSource: KM.ddlModel.cmg,
            value: (<insert condition>) ? "true" : "false"
        });
}

If you condition is more complicated you can do: 如果您的条件更为复杂,则可以执行以下操作:

function evaluateCondition() {

    var returnValue;

    // code to decide what the returnValue is

    return returnValue;
}



KM.ddlModel.bind("loaded", function () {

        var value = evaluateCondition();

        $("#dvDDL").kendoDropDownList({
            dataTextField: "Text",
            dataValueField: "Value",
            dataSource: KM.ddlModel.cmg,
            value: value 
        });
}

Or alternatively you can set if after the drop down list is initialised if you have a reference to the drop down list, like: 或者,您可以设置是否在初始化下拉列表后是否引用了下拉列表,例如:

myDropDownList.value(evaluateCondition());

However you cannot set the value: configuration property to a function. 但是,您不能将value:配置属性设置为函数。 This is because the value of the value: property is used by assignment and it is not called like a function. 这是因为value:属性的value:由赋值使用,而不像函数那样被调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM