0

我正在尝试在使用 Phonegap 和 Sencha touch2 进行编程时如何从服务器获取数据。

我正在尝试从 Google Weather API 获取一些天气数据。

我有一个带有列表的面板,现在应该显示 day_of_week 数据。但我找不到如何从属性中获取数据。如果您查看http://www.google.com/ig/api?weather=zonhoven上的 xml,您可以看到星期几表示为:

所以我得到了以下代码:

Ext.define('WeerBe.view.mainTabs.TestPage', {
extend : 'Ext.navigation.View',
xtype : 'testPage2',

config : {
    title : 'Test Page2',
    iconCls : 'info',

    scrollable : true,

    items : [{
        xtype : 'list',
        itemTpl: '{day_of_week}',

        store : {
            autoLoad: true,

            fields : ['day_of_week'],


            proxy : {
                type : 'ajax',
                url : 'http://www.google.com/ig/api?weather=zonhoven',
                reader : {
                    type : 'xml',
                    root : 'weather',
                    record: 'forecast_conditions'
                }
            }
        }
    }]
}
})

列表应该包含 4 条记录,但它不显示数据,因为 day_of_week 节点本身是空的并且数据在 data 属性中。

如何获取属性数据?

4

1 回答 1

0

我运行了您的代码并检查了控制台日志。

这是抛出的错误:

XMLHttpRequest 无法加载 http://www.google.com/ig/api?weather=zonhoven&_dc=1336560194441&page=1&start=0&limit=25。Access-Control-Allow-Origin 不允许来源http://localhost.com 。

该错误是因为您发出的ajax请求具有跨域跨域资源共享。

因此,将代理类型更改为'jsonp'

proxy : {
      type : 'jsonp',
      url : 'http://www.google.com/ig/api?weather=zonhoven',
      ....
      ....
于 2012-05-09T10:47:44.930 回答