PDA

View Full Version : ExtJS 4 GRID XML from URL



pedro.osorio
5 Jun 2013, 8:04 AM
Hello all,

I need some help to use a XML from a URL (daily updated) to a extjs 4 grid.

The XML url:
http://services.web.ua.pt/sas/ementas?date=day&place=estga&format=xml

How can I set the fields?

Example:
Ext.define('Book',{
extend: 'Ext.data.Model',
fields: [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
{name: 'XPTO1', mapping: ' XPTO2 > XPTO1'},
'XPTO3', 'XPTO4', 'XPTO5'
]}


How can I know from that URL what's the fields that I need to map?

Thank you very much for your help.
BR,

Pedro Costa

slemmon
7 Jun 2013, 9:29 AM
What fields are you wanting from that data?
Sopa, Prato carne, Prato peixe, Prato dieta, Buffet de Saladas, Diversos, Sobremesa, Bebidas?

The XML from the URL in your post:


<result request="/sas/ementas" request_timestamp="1370625894">
<menus zone="estga" type="day">
<menu canteen="Refeitório ESTGA" meal="Almoço" date="Fri, 07 Jun 2013 12:00:01 +0100" weekday="Friday" weekdayNr="5" disabled="0">
<items>
<item name="Sopa">Creme de cenoura</item>
<item name="Prato carne">Peru estufado com ervilhas e batata assada</item>
<item name="Prato peixe">Carapau à lagareiro</item>
<item name="Prato dieta">Carapau grelhado e batata cozida</item>
<item name="Buffet de saladas">Saladas diversas</item>
<item name="Diversos">Pão de mistura</item>
<item name="Sobremesa">Fruta da época ou iogurte</item>
<item name="Bebidas">Água mineral</item>
</items>
</menu>
<menu canteen="Refeitório ESTGA" meal="Jantar" date="Fri, 07 Jun 2013 12:00:01 +0100" weekday="Friday" weekdayNr="5" disabled="0">
<items>
<item name="Sopa">Creme de cenoura</item>
<item name="Prato carne">Escalopes de porco com massa fusilli</item>
<item name="Prato peixe" />
<item name="Prato dieta">Escalopes de porco com massa fusilli</item>
<item name="Buffet de saladas">Saladas diversas</item>
<item name="Diversos">Pão de mistura</item>
<item name="Sobremesa">Fruta da época ou iogurte</item>
<item name="Bebidas">Água mineral</item>
</items>
</menu>
</menus>
</result>

pedro.osorio
7 Jun 2013, 9:36 AM
That's right Slemmon.
I need to get the:
Sopa, Prato carne, Prato peixe, Prato dieta, Buffet de Saladas, Diversos, Sobremesa, Bebidas

Could you help me?

Thank you very much.
BR,
Pedro

slemmon
7 Jun 2013, 12:37 PM
Here is how you'd map the fields using the data you're working with:



Ext.define('User', {
extend: 'Ext.data.Model',
fields: [{
name: 'Sopa',
mapping: 'items > item[name=Sopa]'


// and then the rest of the fields using the same syntax as Sopa
}]
});


var store = Ext.create('Ext.data.Store', {
model: 'User',
proxy: {
type: 'ajax',
url : 'data/xml.xml',
reader: {
type: 'xml',
record: 'menu',
root: 'menus'
}
}
});

pedro.osorio
7 Jun 2013, 1:14 PM
Slemmon, thank you very much for your precious help!
Know I understand how to use Ext.data.Model with a XML like that.

Thank you for your time.

BR,
Pedro