javascript - KendoUI ComboBox selecting Option based on Datasource -
i need code.
the code json response php script , create combobox based on content.
this works... problem need define option selected default, in case, because form edit form.
javascript:
dsource = new kendo.data.datasource({ transport: { read: { url: url, datatype: "json" } }, schema: { model: { fields: { value: {type: "number"}, text: {type: "string"} } } } }); var combobox = $(obj).kendocombobox({ placeholder: "selecione", datatextfield: "text", datavaluefield: "value", filter: "contains", minlength: 3, datasource: dsource });
the json returned php looks this:
[{"value":3,"text":"blue"},{"value":4,"text":"red"},{"value":5,"text":"pink"}]
what need select option based on json, like:
[{"value":3,"text":"blue", "selected":true},{"value":4,"text":"red"},{"value":5,"text":"pink"}]
in case blue option selected default.
i tried means can think of...
you can try this..
//[{"value":3,"text":"blue", "selected":true},{"value":4,"text":"red"},{"value":5,"text":"pink"}] function getselectedtagvalue() { var = null; (i = 0; dsource.length > i; += 1) { if (dsource[i].selected == 'true') { return dsource[i].text; } } return null; }; $("#kendoitems").kendocombobox({ datatextfield: "text", datavaluefield: "value", datasource: data }); var combobox = $(obj).kendocombobox({ placeholder: "selecione", datatextfield: "text", datavaluefield: "value", filter: "contains", minlength: 3, datasource: dsource }); combobox.value(getselectedtagvalue());
hope helps,
regards,
Comments
Post a Comment