4

我遇到的问题是,在第一次加载页面期间,我想从 cookie 中读取值(如果找到),我想更改存储在 cookie 中的主题。不仅想更改它们,而且我还想在组合框中选择该项目,以便它与应用的它们同步。

在构建组合框时,如何在初始页面加载期间选择特定项目?

$(document).ready(function () {

   var initialized = false;
        // theme chooser drop-down
        var cmb=$(".themeChooser").kendoDropDownList({
            dataSource: [
                    { text: "Default" },
                    { text: "BlueOpal" },
                    { text: "Bootstrap" },
                    { text: "Silver" },
                    { text: "Uniform" },
                    { text: "Metro" },
                    { text: "Black" },
                    { text: "MetroBlack" },
                    { text: "HighContrast" },
                    { text: "Moonlight" }
            ],
            dataTextField: "text",
            dataValueField: "value",
            change: function (e) {

                $.cookie('selectedTheme', theme);
                changeTheme(theme);

            }
        });

        theme = ($.cookie('selectedTheme') || "default").toLowerCase();
        //Not sure how to trigger the select of combobox
        cmb.value(theme);  // no effect                       
});
4

2 回答 2

9

获取下拉列表的引用

var dropdownlist = $("#Instrument").data("kendoDropDownList");

如果您知道可以使用的索引:

// selects by index
dropdownlist.select(1);

如果没有,请使用:

// selects item if its text is equal to "test" using predicate function
dropdownlist.select(function(dataItem) {
    return dataItem.symbol === "test";
});

检查这个http://jsfiddle.net/OnaBai/mRmNJ/

于 2013-12-30T10:51:52.093 回答
1

剑道文档

我相信在你的情况下,它会是这样的一些电话:

//trigger the select of combobox 
cmb.select(function(dataItem) {
    return dataItem.text === theme;
});

或者只是在对象初始化器中设置value属性

value = ($.cookie('selectedTheme') || "default").toLowerCase(),
于 2013-12-30T02:54:03.713 回答