javascript - How to manually add an item into datasource in Kendo UI Combobox -
I have a combo box which is populated by the JSON string derived from servlet.
$ (document) .ready (function () {// Knboboks Init (from Sserlet) var combo Boksdetasors = new Kendodeta. Datasors ({transport: {read: {url: "net / samso / action / common / comboAction? (field: {key: {type: "string"}, value: {type: {@}: "string"}}}}}; // manually an item combo Boksdeta from Add source. ({key: "062", say: "Total"}); // Comboboks $ begin ( "# Cb_srchgt_io_gb"). KendoComboBox ({data source comboBoxDataSource, dataTextField: "value" data Valufild: "Key "})}); As long as I data source comboBoxDataSource.add ({key: "062", the value: "The manually try to add an item to the total"}), then the code works fine Code>. When the item is added, it gets rid of other objects which had populated data from the data source in JSN.
the problem is that Datasor has been asynchronously from scratch, I mean, when you Comboboks early Su Start loading with the form, but until the data is received from the server, the operation is not complete, and only then, when you should invite that element, it takes milliseconds or seconds to load from a server Therefore, the addition statement at the end of the sample code is also not acceptable. If you want to add an element, then getting it from the server, you can use it:
$ (document) .ready (function () {// Combobox Init (the Servlet) var comboBoxDataSource = new kendo.data.DataSource ({Transport: {read: {url: "net / samso / action / common / comboAction? Flag = SRCHGT_IO_GB", // url remote data Type in the source data: "json", type: 'gET'}}, schema: {model: {field: {key: {type: "string"}, value: {type: "string"}}}, Data: Function (results) {// Manually add an item result. Push ({key: "062" value: "A Start the Combobox $ ("# cb_srchgt_io_gb"). KendoComboBox ({Datasource: comboBoxDataSource, dataTextField: "value", dataValueField: "key"})}); You can do the same thing using the requestEnd event and e.response : request end : E.response.push ({key: "062", value: "total"});} In fact, any event is removed after receiving the data from the server is OK.
Comments
Post a Comment