Tuesday, June 24, 2008

Assigning values to vars in Dojo

In dojo you can populate vars by using below syntax. Here continentStore is populated using countries.json file, method using is dojo.data.ItemFileReadStore.

<div dojoType="dojo.data.ItemFileReadStore" jsId="continentStore"
url="../tests/_data/countries.json"></div>


I have come across situations where I wanted to get this values assigned to just plain variables without using divs and dojoType etc. So this is how we do it.
var waveTreeDataSource = new dojo.data.ItemFileReadStore( {
data:{ identifier: 'name',
label: 'name',
items: [
{ name:'XXX', type:'media',
children:[{name:'A2P',children:[{name:'MCA'},{name:'Forex'}]},
{name:'P2P'}]},
{ name:'YYY' , type:'media',
children:[{_reference:'Test'},]},
{ name:'Test', type:'person', children:[{name:'test'}] },
{ name:'Dilan', type:'person'},
{ name:'Anuruddha', type: 'person'},
{ name:'KD', type: 'person'}
]
}
});

Just remember that we need to include same data structure in JSON file but we have to include it as object with data attribute as shown above. For more information take look at API documentation for dojo.data.ItemFileReadStore.

No comments: