3

我很难理解为什么我在 Sencha 视图中没有得到任何东西。我相信在服务器和 Sencha 代理之间传输的 json 存在问题。我有一个用 node 和 express 编码的服务器和一个在 Sencha 中的代理阅读器。但是 Sencha 无法读取数据。

服务器端:

    app.get('/weather/fulljson',function(req, res) { 
    var obj = {data: [{ from_user: 'world', data: 'inter' }, { from_user: 'world2', data: 'interw' }, { from_user: 'world3', data: 'interw' }]};

    jsonP = false;
    var cb = req.query.callback;
    console.log(cb);
    if (cb != null) {
        jsonP = true;
        res.writeHead(200, {
            'Content-Type': 'text/javascript', 
            'connection' : 'close'
        });
    } else {
        res.writeHead(200, {'Content-Type': "application/x-json"});
    }
if (jsonP) {
    res.end(cb +  "(" + JSON.stringify(obj) + ");" );
}
else { res.end(JSON.stringify(obj));
}
 )};

});

煎茶视图:

Ext.define('Epic.view.Weather', {
    xtype: 'graph',
    extend: 'Ext.DataView',
    //requires: ['Epic.store.SWeather'],
    requires: ['Epic.model.MWeather', 'Ext.data.proxy.JsonP'],
    config: {
        store: {
        autoLoad: true,
        fields: ['from_user', 'data'],

        proxy: {
            type: 'jsonp',
            url: 'http://localhost:3000/weather/fulljson',
            reader: {
                type: 'json',
                rootProperty: 'data'
            }
        }
    } 
    },

            itemTpl: '{from_user}'
});

铬响应:

Ext.data.JsonP.callback1({"data":[{"from_user":"world","data":"inter"},{"from_user":"world2","data":"interw"},{"from_user":"world3","data":"interw"}]});

但是视图中什么也没有出现。

4

1 回答 1

0

您在加载后检查过您的商店吗?它是否包含您发送的数据?如果是 - 在这种情况下,您的观点有问题。您可以使用调试器工具并获取您的组件并检查存储。您还可以展示您的模型 Epic.model.MWeather 吗?实际上,如果您有模型,则不必向商店添加字段。

于 2012-12-09T20:41:59.933 回答