我正在試驗如何在使用Phonegap和Sencha touch2進行編程時從服務器獲取數據。使用sencha touch從xml獲取屬性數據2
我試圖從Google Weather API獲取一些天氣數據。
我得到一個列表,它應該顯示day_of_week數據的列表。但我無法找到我如何從屬性獲取數據。如果你看一下XML在http://www.google.com/ig/api?weather=zonhoven你可以看到,本週的日表示爲:
所以我得到了下面的代碼:
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條記錄,因爲它應該,但它不」 t顯示數據,因爲day_of_week節點本身爲空,且數據在data屬性中。
如何獲取屬性數據?
奇怪的是,我之前沒有收到這個錯誤,現在我也是這樣。 但是,當我將AJAX更改爲jsonp時,控制檯中出現以下錯誤: 未捕獲的SyntaxError:意外的令牌< 可能是因爲它期望json而不是XML –
這並不重要。 'jsonp'請求僅用於請求數據跨域 –
仍不能解決意外的令牌