1. Start by defining a model to define the data we are loading:
Ext.define('Flickr', {
extend: 'Ext.data.Model',
fields: [{
name: 'title',
type: 'string'
}, {
name: 'link',
type: 'string'
}]
});
2. Create a store with a JSONP proxy:
var JSONPStore = Ext.create('Ext.data.Store', {
model: 'Flickr',
proxy: {
type: 'jsonp',
url:
'http://api.flickr.com/services/feeds/photos_public.gne',
callbackKey: 'jsoncallback',
extraParams: {
tags: 'swan',
tagmode: 'any',
format: 'json'
}
},
reader: {
type: 'json',
root: 'items'
}
});
3. Load data into the Store by calling the store's load method:
JSONPStore.load();
4. Finally, once the load has finished check to make sure that the data has loaded
correctly by returning the first record from the Model:
JSONPStore.on('load', function(){
var record = JSONPStore.getAt(0);
console.log(record.data.title + ' ' + record.data.link);
}, this);
댓글 없음:
댓글 쓰기