Simple question here. How could I place this JSON string into an Ext.data.Store?
{
"elements":[
{
"element":{
"name":"value 1",
"id":"element 1",
"attributes":[
{
"attrname":"id",
"attrvalue":"This is the ID"
},
{
"attrname":"name",
"attrvalue":"This is the name"
},
{
"attrname":"description",
"attrvalue":"This is the description"
},
{
"attrname":"table_name",
"attrvalue":"This is the table"
}
]
}
}
}
This is a simplified version of my question: Placing JSON response elements into a store- Ext JS
Cheers!
Since the JSON is coming back from the server, the first thing you'll need to do is to deserialize it from a JSON-formatted string into an object that you can navigate. Assuming that it's valid JSON, you can simply do this by using Ext.decode().
This will give an object that has an array of objects at the "elements" key. Simply loop over the elements array and create a new model instance that can be inserted into your store.
Here's a link to a live example: https://fiddle.sencha.com/#fiddle/3u6
And here's the code from that example: