
Untitled
By: a guest on
Jul 17th, 2012 | syntax:
None | size: 1.21 KB | hits: 11 | expires: Never
Sencha Touch - Store JSON file containing Array [closed]
[{"target": "stats.server1", "datapoints": [[22, 34], [99, 12], [13, 15], [56, 12], [34, 2], [13, 23], [23, 34], [55, 88]]},{"target": "stats.server2", "datapoints": [[22, 34], [99, 12], [13, 15], [56, 12], [34, 2], [13, 23], [23, 34], [55, 88]]}]
// A reader defines how to process incoming data.
Ext.define('My.PointsReader', {
extend: 'Ext.data.reader.Json',
alias: 'reader.points',
getData: function(data) { // overriding
data = this.callParent(arguments);
var result = [];
Ext.each(data, function(entry) {
Ext.each(entry.datapoints || [], function(point) {
result.push({
xValue: point[0], yValue: point[1],
target: entry.target
});
});
});
return result;
}
});
// A store is always Ext.data.Store (or TreeStore, for trees).
// But its proxy, reader and writer can be customized.
var store = Ext.create('Ext.data.Store', {
fields: ['xValue', 'yValue', 'target'],
proxy: {
type: 'ajax',
url: 'test.json',
reader: 'points'
}
});
store.load();