0
你好,我是一個使用sencha開發移動應用程序的新手。在我發佈之前,我已經做了一項研究,但我沒有找到任何解決方案。我試圖從它具有以下格式如何從Ext.data.Store裏面的xml中獲取數據
<?xml version="1.0" encoding="UTF-8"?>
<rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
>
<channel>
<title></title>
<link></link>
<description></description>
<language>en-us</language>
<pubDate>Mon, 08 Jul 2013 13:12:39 +0000</pubDate>
<lastBuildDate>Mon, 08 Jul 2013 13:12:39 +0000</lastBuildDate>
<managingEditor></managingEditor>
<item>
<position>1</position>
<image>img/2.png</image>
<name>Sun</name>
<small_desciption>dfsfsdfsdf</small_desciption>
</item>
<item>
<position>2</position>
<image>img/2.png</image>
<name>Hot</name>
<small_desciption>fsdfdsfsdf</small_desciption>
</item>
........
</channel>
</rss>
,這裏是我的代碼
Ext.regModel('test', {
fields: [{
name: 'image',
type: 'string'
}, {
name: 'name',
type: 'string'
}, {
name: 'small_desciption',
type: 'string'
}, {
name: 'position',
type: 'string',
}]
});
ToolbarDemo.views.Testtab = Ext.extend(Ext.Panel, {
title: "Test",
iconCls: "test",
styleHtmlContent: true,
style:"background-color:#FFFFFF;",
dockedItems: [
{
xtype: "toolbar",
title: "Test",
items : [
{ xtype : 'spacer' },
// { xtype : 'spacer' },
],
},
],
layout: {
type: 'fit'
},
initComponent: function() {
this.setLoading(true,true);
var proxyUrl = 'http://mydomain/newsfeed/'
var store = new Ext.data.Store({
model: 'test',
proxy: {
type: 'ajax',
url: proxyUrl,
reader: {
type: 'xml',
record: 'item',
}
},
datachanged: function(){
var items = [];
store.each(function(rec){
items.push({
html: [
'<div class="main"><div class="thumb"><div class="contain">{position}</div><div class="image"><img src="http://mydomain/{image}.jpg" width="280" height="100"></div></div><div class="mainentry"><div class="maintitle">{name}</div><div class="description">{small_desciption}</div></div></div>',
]
});
});
}
});
store.read();
ToolbarDemo.views.Testtab.superclass.initComponent.call(this);
} });
Ext.reg('testtab', ToolbarDemo.views.Testtab);
我在做什麼錯了一個XML獲取數據?
謝謝
並寫在HTML?就像這個例子一樣?當你以xml格式得到響應並解析它時,你可以使用這個例子嗎?http://www.sencha.com/forum/showthread.php?140552-Ext.data.Store-and-XML –
@ George答案只給出了從xml獲取數據的想法。 – Dev