2012-12-09 45 views
3

我在努力理解为什么我在Sencha视图中没有任何东西。我相信在服务器和Sencha代理之间传输的json存在问题。我有一个服务器编码节点和表达和在Sencha代理阅读器。但Sencha无法读取数据。JSON响应:节点服务器和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)); 
} 
)}; 

}); 

煎茶查看:在Chrome

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"}]}); 

但没有出现在视图中。

+0

另外,你需要JSONP类型吗?你会使用crossite sripting? – Psycho

回答

0

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

+0

感谢您的回复。如何检查商店是否有数据而不使用DataView? – Fatfly

+0

感谢您的回复。我目前没有使用该模型。如果我删除它,没有什么改变。为了检查商店,你是在谈论“资源”选项卡和本地存储?如果它正在工作,那么会出现什么结果? – Fatfly

+0

你可以使用Ext.getCmp('id')和你可以从DOM获得的Id。 – Psycho