在商店中加载Json以在List Sencha Touch 2 jsonp上显示它

时间:2012-12-18 09:03:05

标签: sencha-touch-2 jsonp store

这是我的模特

Ext.define("StockWatch.model.Market", {
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' },
    ]
}
});

这是我的商店

Ext.define("StockWatch.store.Markets", {
    extend: "Ext.data.Store",
    requires: ["Ext.data.proxy.LocalStorage", "Ext.data.proxy.JsonP", "StockWatch.model.Market"],
    config: {
        model: "StockWatch.model.Market",
        autoLoad : true,
        proxy : {
            type : 'jsonp',
            url : 'http://money.rediff.com/money1/current_status_new.php?companylist=17023928%7C17023929&id=1354690151&Rand=0.6305125835351646',
            reader:{
                    type:'json',
                    rootProperty:''
                }
        }
    }
});

我无法将数据放到我的列表中,可能在某处提取数据是错误的。 指导我找到解决方案。 我也在使用pull to refresh list插件,因此每次下拉列表时我都会自动加载数据,或者我必须在那里写一些东西吗?

提前thnx

修改 我也在控制台中收到此警告

Resource interpreted as Script but transferred with MIME type text/html: "http://money.rediff.com/money1/current_status_new.php?companylist=17023928%7C17023929&id=1354690151&Rand=0.6305125835351646&_dc=1355822361093&page=1&start=0&limit=25&callback=Ext.data.JsonP.callback1". 

2 个答案:

答案 0 :(得分:1)

使用callbackKey

callbackKey:指定将发送到服务器的GET参数,该服务器包含要在请求完成时执行的函数名称。默认为回调。因此,一个常见的请求将是url?callback = Ext.data.JsonP.callback1

的形式

默认为:“回调”

答案 1 :(得分:0)

您需要在JSONP的回调函数中包装JSON响应。它看起来像你的远程调用返回这个,尝试指定一个回调参数 - 否则如果远程服务器不允许这样做,你需要将它传递给另一个服务器以将其包装在回调函数中。

此外,您在帖子底部提到的警告也不用担心。它不会造成任何问题。