Populating dropdownlist with JSON

1 Answer 39 Views
DropDownTree
Roel
Top achievements
Rank 1
Iron
Veteran
Roel asked on 18 Jun 2021, 12:43 PM | edited on 18 Jun 2021, 12:44 PM

I like to bind to this JSON below. De JSON should fill the dropdownlist. The first item would have a value of 0 and a text of Unknown.

{
    "0": "Unknown",
    "1": "Not executed",
    "2": "Not reported",
    "3": "Executed and Reported",
    "4": "Not to be executed",
    "select": null,
    "table": null
}

But somehow the dropdownlist only accepts JSON like:

[
    {​ "value": 0, "text": "Unknown" },
    {​ "value": 1, "text": "Not executed" }​,
    etc.,
]

Is it possible to configure the ddl with the most above JSON?

1 Answer, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 23 Jun 2021, 09:19 AM

Hello Roel,

Note that the dataSource of the DropDownTree widget could be a JavaScript object which represents a valid data source configuration, a JavaScript array, or existing kendo.data.HierarchicalDataSource instance. The dataTextField and dataValueField should point to a field in the data. 

The second example from your reply is actually the correct way to set the dataSource in the DropDownTree in order to have an item with value = 0 and "Unknown" as text.

You could read more about the data binding in the DropDownTree in the articles linked below:

- https://docs.telerik.com/kendo-ui/controls/editors/dropdowntree/binding/data-binding

- https://docs.telerik.com/kendo-ui/controls/editors/dropdowntree/binding/binding-to-flat-data 

Let me know in case you have additional questions on the matter.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
DropDownTree
Asked by
Roel
Top achievements
Rank 1
Iron
Veteran
Answers by
Neli
Telerik team
Share this question
or