Is it possible to provide JSON Array as data to dojo.data.ItemFileReadStore
I have JSON array like [ ["jhon", "newyork", "9999"], ["bob", "chicago", "5555"], ["rolf", "germany", "1111"] ]
and i want to provide this JSON Array to dojo.data.ItemF开发者_Go百科ileReadStore.
IS it possible to send this array?
It's possible to feed a JavaScript object directly as data to an ItemFileReadStore instance via the data
attribute (alternatively to via url
), but it's important to understand that whether you're providing the data directly or via XHR, your data will still need to conform to the format that ItemFileReadStore expects.
http://dojotoolkit.org/reference-guide/dojo/data/ItemFileReadStore.html#input-data-format
There's actually an example further down the same page that shows an ItemFileReadStore being instantiated with an object being fed directly via the data
parameter:
http://dojotoolkit.org/reference-guide/dojo/data/ItemFileReadStore.html#custom-sorting
To elaborate based on the JSON you gave as example, it'd probably be far more meaningful to provide something like this to the store:
var store = new dojo.data.ItemFileReadStore({ data: {
identifier: 'id'
items: [
{
id: 9999,
name: "jhon",
location: "newyork"
},
...
]
}});
If you don't have control over the array you're being given, I suppose you could consider writing a function to convert it before feeding it to the store.
精彩评论