PDA

View Full Version : Loading Json in Store to display it on List Sencha Touch 2



arunsathyan
27 Dec 2012, 1:35 AM
i am not able to load data from store to List.
My Code



Ext.define('Contact', {
extend: 'Ext.data.Model',
config: {
idProperty: 'CompanyCode',
fields: [
{ name: 'CompanyCode', type: 'string' },
{ name: 'LastTradedPrice', type: 'string' },
{ name: 'PercentageDiff', type: 'string' },
{ name: 'FiftyTwoWeekHigh', type: 'string' },
{ name: 'FiftyTwoWeekLow', type: 'string' },
{ name: 'ChangePercent', type: 'string' },
{ name: 'Change', type: 'string' },
{ name: 'MarketCap', type: 'string' },
{ name: 'High', type: 'string' },
{ name: 'Low', type: 'string' },
{ name: 'PrevClose', type: 'string' },
{ name: 'OpenInterest', type: 'string' },
{ name: 'MarketLot', type: 'string' },
{ name: 'ChangeInOpenInterest', type: 'string' },
{ name: 'LastTradedTime', type: 'date', dateFormat: 'c' }
]
}
});


var store = Ext.create('Ext.data.Store', {
extend: ["Ext.data.proxy.JsonP"],
model: Contact,
sorters: 'CompanyCode',


grouper: {
groupFn: function(record) {
return record.get('CompanyCode')[0];
}
},


proxy : {
type : 'jsonp',
url : 'http://money.rediff.com/money1/current_status_new.php?companylist=17023928|17023929&id=1354690151&Rand=0.6305125835351646',
callbackKey: 'callback',
reader:{
type:'json',
rootProperty:''
}
}
});


Ext.create('Ext.List', {
fullscreen: true,
itemTpl: '<div class="contact">{CompanyCode} <strong>{LastTradedPrice}</strong></div>',
store: store,
grouped: true
});



Service Url

http://money.rediff.com/money1/current_status_new.php?companylist=17023928|17023929&id=1354690151&Rand=0.6305125835351646
Json Response

[{"CompanyCode":"17023928","LastTradedPrice":"19,406.69","Volume":"0","PercentageDiff":"-0.06","FiftyTwoWeekHigh":"19,612.18","FiftyTwoWeekLow":"15,358.02","LastTradedTime":"27 Dec,14:52:48","ChangePercent":"-0.06","Change":"-10.77","MarketCap":"0.00","High":"19,504.40","Low":"19,375.52","PrevClose":"19,417.46","OpenInterest":"","MarketLot":"","ChangeInOpenInterest":"","Symbol":null}]

mitchellsimoens
29 Dec 2012, 7:20 AM
This is because the response doesn't look like it's returning JsonP, just returning Json.

arunsathyan
30 Dec 2012, 9:17 PM
Thnaks Mitchell,
is there any other option to read this and bind to store? i need to access this json from a native app.