This is a migrated thread and some comments may be shown as answers.

Key Pairs in the Data Source

2 Answers 61 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Bryan
Top achievements
Rank 1
Bryan asked on 15 Jul 2015, 07:25 PM

I have a JSON string that I'm trying to convert to a datasource then bind to one of the controls. The string looks like this:

var TestData =  [ {"Category": "1", "Attributes": [{"Attribute": "A", "Attribute": "B", "Attribute": "C" }] }]

 then the datasource declaration is like this:

    var thisData = new kendo.data.DataSource({
        data: $.parseJSON(TestData),
        schema: {
            model: {
                fields: {
                    Category: { type: 'string' },
                    Attributes: {
                        Attribute: { type: 'string' }
                    },
                }
            }
        }
    })‚Äč

 When I bind to a listview and try to loop through the values in a template, it always tells me the length of the Attributes list is 1 and displays the last value ("C"). Is there something wrong in the declaration? 

2 Answers, 1 is accepted

Sort by
0
Accepted
T. Tsonev
Telerik team
answered on 17 Jul 2015, 01:57 PM
Hi,

The Attributes array consists of a single element so that's working pretty much as expected.
The Attribute key is defined multiple times and consequently only the last value is taken into account.

Perhaps what you mean to serialize is:
[ {"Category": "1", "Attributes": [{"Attribute": "A"}, {"Attribute": "B"}, {"Attribute": "C"}] }]
 
I hope this helps.

Regards,
T. Tsonev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bryan
Top achievements
Rank 1
answered on 17 Jul 2015, 02:04 PM
That was it. Thanks!
Tags
Data Source
Asked by
Bryan
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Bryan
Top achievements
Rank 1
Share this question
or