I have a kendo combobox created using an MVC wrapper like so:

@Html.Kendo.ComboBox().Name("Well");

I want to update the data manually using a json array stored in javascript (not from an ajax query) - I came across this code which almost works except that I get [object Object] 3 times in the ComboBox instead of the 'text' value from the json array:

$("#Well").data("kendoComboBox").dataSource.data([{text: "i1", value: "1"}, {text: "i2", value: "2"}, {text: "i3", value: "3"}]);
$("#Well").data("kendoComboBox").dataSource.query();
有帮助吗?

解决方案

It seems there is no default for the text/value fields so adding:

@Html.Kendo.ComboBox().DataTextField("text").DataValueField("value").Name("Well");

fixes the issue.

其他提示

Following helped me to solve the problem of dynamically updating the kendo combobox datasource,

var combobox = $("#selector").data("kendoComboBox"); 
if(combobox){
    combobox.destroy();
    combobox.dataSource.data(NewDatasourceObject);
    combobox.refresh();
}    
 $("#Well").kendoComboBox({
            placeholder: "Select...",
            dataTextField: "text",
            dataValueField: "value",
            filter: "contains",
            autoBind: true,
            dataSource: {
                //type: "odata",
                serverFiltering: true,
                transport: {
                    read: { url: "../your_json_url" }
                }
            }
        });
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top