首先,我在这里阅读这个简短的帮助主题:点击
它使用与PHP一起构建的JSON文件,看起来像这样:
{ name:'Italy', type:'country' },
{ name:'North America', type:'continent',
children:[{_reference:'Mexico'}, {_reference:'Canada'}, {_reference:'United States of America'}] },
{ name:'Mexico', type:'country', population:'108 million', area:'1,972,550 sq km',
children:[{_reference:'Mexico City'}, {_reference:'Guadalajara'}] },
{ name:'Mexico City', type:'city', population:'19 million', timezone:'-6 UTC'},
{ name:'Guadalajara', type:'city', population:'4 million', timezone:'-6 UTC' },
{ name:'Canada', type:'country', population:'33 million', area:'9,984,670 sq km',
children:[{_reference:'Ottawa'}, {_reference:'Toronto'}] },
Run Code Online (Sandbox Code Playgroud)
所以,假设我现在想"回应"这个列表中的所有城市......这对我来说没问题!:-)但我完全混淆了如何访问人口例如!我怎样才能创造一个回声的功能:"墨西哥城:人口:'1900万'时区:' - 6 UTC'"例如?
set*_*eth 10
你可以这样做:
var data = { items: [{ name:'Mexico City', type:'city', population:'19 million', timezone:'-6 UTC'}]};
var store = new dojo.data.ItemFileReadStore( { data: data });
// or just omit query object if you want all
store.fetch( { query: { name: 'Mexico City' },
onItem: function(item) {
console.log( store.getValue( item, 'name' ) );
console.log( 'population: ', store.getValue( item, 'population' ) );
console.log( 'timezone: ', store.getValue( item, 'timezone' ) );
}
});
Run Code Online (Sandbox Code Playgroud)
请注意,您的数据应该包含一个包含实际数据数组的项目键.
不可否认,dojo数据存储起初有点难以理解,但是一旦你记得数据可能被懒惰和异步加载就有意义了.这就是为什么所有项目请求都经过fetch并检索值的原因getValue.
Dojocampus对ItemFileReadStore有一个很好的描述.
| 归档时间: |
|
| 查看次数: |
27233 次 |
| 最近记录: |