PDA

View Full Version : Loading xml-string in a store of a list



tariqahmed
21 Jan 2011, 1:44 AM
Hi,

I am new to Sencha Touch and ExtJS and have a question on how to load my data from the backend in a store for showing it in a List.:)

My App contains a list and a button. After clicking on the Button, I want to show the data in the List.
In this case I must use my own service for loading data. It returns a simple xml-String.
For parsing I wrote the fellowing model, I thought MemoryProxy should be right, but I'm not sure about that:


Ext.regModel("NewsRecord", {
fields: [
'title',
'description',
'link',
'pubDate'
],
proxy:
{
type: 'memory',
reader: {
type: 'xml',
record: "item",
}
}
});

My List and the loading function:


myapp.views.List = Ext.extend(Ext.List, { ...
initComponent: function()
{
Ext.applyIf(this,
{
store: new Ext.data.Store({
model: "NewsRecord",
autoLoad: false
})
});
myapp.views.List.superclass.initComponent.apply(this, arguments);
this.enableBubble('selectionchange');
}
...
/** Simplified.... */
onRefresh: function()
{
var data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><channel><title>News</title><item><title>Wochenende startet mit Schnee und Regen</title> <link>http://www.mylink.de</link><description><![CDATA[Sonst ist es heiter bis wolkig und meist trocken.[...]]]></description><pubDate>01 Jan 2011 11:00:37 +0000</pubDate></item></channel>";
var doc = (new DOMParser()).parseFromString(myService.Content, "text/xml");
var store = list.store;
store.loadData(doc, false);
}


I think the Main-Problem is that the Store don't use the Reader for loading Data. Maybe i'm missunderstanding the concept of loading data, but how can i make it work.

Hopefully you could help me:-/
Tariq

AndreaCammarata
21 Jan 2011, 2:44 AM
Hi tariqahmed and welcome.
I really suggest you to read this example at Sencha Touch API Docs before to start ;)

http://dev.sencha.com/deploy/touch/docs/?class=Ext.data.XmlReader

When you understand how it works, you can apply it to your code according to your needs.
Hope this helps.

tariqahmed
21 Jan 2011, 7:10 AM
Okay I changed the source to:


Ext.regModel("NewsRecord", {
fields: [
'title',
'description',
'link',
'pubDate'
]
});

store: new Ext.data.Store({
model: "NewsRecord",
proxy:
{
type: 'ajax',
reader: {
type: 'xml',
record: 'item',
root: 'channel'
}
}
})


But the Problem is the same, the proxy is not used for loading data through loadData Methode from store.
How I can push the data into the store? Should I first create a XmlReader for parsing and then load the data in to the Store?!? But then the proxy don't make sense...

LemonMty
5 Mar 2011, 12:42 PM
Hi... I think your missing to provide the path and name of the file wich contains the data... just like this


store: new Ext.data.Store({
model: "NewsRecord",
proxy:
{
url: '[path]/[XmlFileName].xml',
type: 'ajax',
reader: {
type: 'xml',
record: 'item',
root: 'channel'
}
}