Reputation: 11
I was trying to implement Kendodropdowntree , I came across following situation which I am not able to understand
$(dropdowntree).kendoDropDownTree({
placeholder: "Select ...",
height: "auto",
dataSource: //HARD CODED VALUE GOES HERE
});
}
Above example will work fine when , I hard code those datasource values. When I try to pass some variable there it will not work
var datatobind= somedata // data in exact format it is expected
{
$(dropdowntree).kendoDropDownTree({
placeholder: "Select ...",
height: "auto",
dataSource: datatobind
});
}
Even I tried passing variable of following type
var dataSourcetype = new kendo.data.HierarchicalDataSource({
data: datatobind
});
{
$(dropdowntree).kendoDropDownTree({
placeholder: "Select ...",
height: "auto",
dataSource: dataSourcetype.options.data
});
}
But even above also doesn't solve problem, I am not able to get it , why passing exact same variable is not binding to data source.
Upvotes: 1
Views: 360
Reputation: 135
Could you try something like this?
The datasource variable:
var dataToBind = new kendo.data.HierarchicalDataSource({
transport: {
read: {
url: "url/to/your/data",
dataType: "jsonp"
}
},
schema: {
model: {
id: "Id",
hasChildren: "HasChildren" //boolean value
}
}
});
Then your kendoDropDownTree should look like this:
$("#dropdowntree").kendoDropDownTree({
dataSource: dataToBind,
dataTextField: "Name",
dataValueField: "Id",
placeholder: "Select ...",
height: "auto"
});
Note that the id in the datasource variable has to match the one in the dataValueField on the kendoDropDownTree
Upvotes: 0