Reputation: 13
I want to use Datasource data with multiple dropdowns, if I use shared dataSource that makes ajax requests as much as the number of the dropdowns to server. what I need is 1 ajax request and use that data to populate all dropdowns. this code gives me ildata is not defined..
thanks for help.
code example
var ilDataSource= new kendo.data.DataSource({
transport: {
read: {
url: "{{ url('ajax/ilList') }}",
dataType: "json"
}
}
});
ilDataSource.fetch(function(){
var ildata = ilDataSource.data();
});
var iller = $("#iller").kendoDropDownList({
placeholder: "İl Seçiniz",
dataSource : {
data: ildata
},
dataTextField: "il",
dataValueField: "id"
}).data("kendoDropDownList");
I can get data items in function scope but cant get in common scope..
ilDataSource.fetch(function() {
ildata = ilDataSource.data().toJSON();
console.log(ildata); });
Upvotes: 0
Views: 575
Reputation: 109005
ilDataSource.fetch(function(){ var ildata = ilDataSource.data(); });
This defines a local variable ildata
scoped to the anonymous function.
dataSource : { data: ildata },
thus at this point there is no variable/property ildata
.
You need to declare ildata
at a common scope for the two use cases:
var ildata;
ilDataSource.fetch(function(){
ildata = ilDataSource.data();
});
var iller = $("#iller").kendoDropDownList({
placeholder: "İl Seçiniz",
dataSource : {
data: ildata
},
dataTextField: "il",
dataValueField: "id"
}).data("kendoDropDownList");
Whether Kendo can handle this re-use of a single DataSource is another question.
Upvotes: 1