Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
37
rated 0 times [  43] [ 6]  / answers: 1 / hits: 6787  / 10 Years ago, thu, march 13, 2014, 12:00:00

I want to feed a dijit.form.Select (Dojo Select-Box) with a Data-Store (JsonRest). The Problem is, that the JSON-Parser only accepts JSON in this format:



[
{id:1, name:One1},
{id:2, name:Two1}
];


The REST-API of the webapplication we want to call delivers the following JSON:



{
data: [
{id:1, name:One1},
{id:2, name:Two1}
],
total: 2,
start: 0,
sort: name,
order: asc,
size: 2
};


That is why the Select Box does not show any data. Therefore, we need to remove the {data: part and the last part of the JSON message bevore passing it to the Dojo Select Box.



The Data is stored in a JsonRest Object. So the question is how we can remove the first and the last part of the JSON in a way that simply this here is given to the Select-Box:



[
{id:1, name:One1},
{id:2, name:Two1}
];


Thank you for your answers and best regards
Ben


More From » json

 Answers
2

Create a new Array variable from the data for the dojo select seems simplest ...



var restapidataObj = {
data: [
{id:1, name:One1},
{id:2, name:Two1}
],
total: 2,
start: 0,
sort: name,
order: asc,
size: 2
};

var dojoSelectArray = restapidataObj.data;


Now pass dojoSelectArray to dojo


[#46891] Wednesday, March 12, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jacie

Total Points: 490
Total Questions: 111
Total Answers: 105

Location: Mali
Member since Sat, Feb 12, 2022
2 Years ago
;