-
27 Jun 2011 6:12 AM #11
I can't get it to work either. Is there a simple example somewhere?
-
5 Jul 2011 2:03 AM #12
Simple example
Simple example
Figured it out some days ago, here's a pretty simple example for the rest of you:
It doesn't do anything interesting, just load the xml then print the name of the first author.
To access the nested elements use something like this
store.getAt(0).books().each(function(book){
console.log(book);
});
index.js
XML:Code:var App = new Ext.Application({ name: 'Books', useLoadMask: true, launch: function () { Ext.regModel('Book', { idProperty: 'name', fields: [ { name: 'name', type: 'string' }, ], belongsTo: 'Author', proxy: { type: 'memory', reader: { type: 'xml', root: 'books', record: 'book' } } }); Ext.regModel('Author', { idProperty: 'name', fields: [ { name: 'name', type: 'string' }, ], hasMany: [ { model : 'Book', name: 'books', } ] }); store = new Ext.data.Store({ model: 'Author', proxy: { type: 'ajax', url: './books.xml', reader: { type: 'xml', record: 'author', root: 'authors' } } }); store.load(); content = new Ext.form.FormPanel({ items:[ { xtype:'textfield', name: 'name', label:'Author: ' } ] }); Books.views.viewport = new Ext.Panel({ fullscreen: true, layout: 'card', items: [ content ] }); //log the books to console to prove they were loaded setTimeout(function() { content.load(store.getAt(0)); store.getAt(0).books().each(function(book){ console.log(book); }); }, 1000); } });
I could have tidied the code up a bit, but I'm working on a project and don't have time for that.Code:<authors> <author> <name>Author 1</name> <books> <book> <name>Book</name> </book> <book> <name>Book2</name> </book> </books> </author> <author> <name>Author 2</name> <books> <book> <name>Book3</name> </book> <book> <name>Book4</name> </book> </books> </author> </authors>
-
22 Aug 2011 7:04 AM #13
is it possible such a struct to parce ?
<xxx> <author name="Author 1"> <book name="Book1"/> <book name="Book2"/> </author> <author name="Author 2"> <book name="Book1"/> <book name="Book2"/> </author> </xxx>
-
26 Aug 2011 4:26 PM #14Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
With 2.0 just around the corner, I've added this to its backlog to make sure this happens. Almost all of our efforts are focused on 2.x at the moment so it should be a relatively simple thing to drop in
Ext JS Senior Software Architect
Personal Blog: http://edspencer.net
Twitter: http://twitter.com/edspencer
Github: http://github.com/edspencer
-
18 Sep 2011 10:53 AM #15
Please provide a complete working example for nested XML
Please provide a complete working example for nested XML
Please help, I am very depressed, I am already late on a SenchaTouch project and it must be finished by tomorrow. I have spent all weekend working on a nested XML feed and I cannot for the life of me get anything to return from the nested sections.
I was hoping you could please please please give a complete working example?
I have searched and searched but cannot find a single example anywhere.
Taking your example further, I have this:
Ext.regModel('Book',{
fields:[
{name:'bookname',type:'string'},
{name:'pages',type:'int'},
{name:'score',type:'int'}
],
proxy: {
type: 'memory',
reader: {
type: 'xml',
root: 'books',
record: 'book'
}
}
});
Ext.regModel('User',{
fields:[
{name:'userid',type: 'int'},
{name:'username',type:'string'},
{name:'books',type:'string'}
],
//hasMany: {model: 'Book', name: 'books'},
proxy: {
type: 'ajax',
url : urlRizlabProjects,
reader: {
type: 'xml',
root: 'users',
record: 'user'
}
}
});
You are free to completely change everything below but this is roughly what I normally do:
var storage7 = new Ext.data.Store({
model: 'User',
listeners: {
datachanged: function(){
storage7.each(function(rec){
alert(rec.get('username')); //this bit works
//but how do I access the books here please?????????????????????????
});
}
}
});
thank you so much - I have tried to find information about memory records but have got nothing, plus a very long list of pages with people asking about nested xml.
-
18 Sep 2011 1:36 PM #16
I worked it out now...
I worked it out now...
Must have been feeling really tired, and didn't properly try out bobbaluba's example above - it works! I will bookmark this url and post it whenever I see other lost soul's trying to get this working
-
19 Sep 2011 3:14 AM #17
Am I correct to assume that parsing the following XML isn't possible with Sencha Touch 1.0? Seeing as the <section> tags and <production> tags don't have an element surrounding them, which would correspond to the root parameter when you create an XMLReader?
Code:<?xml version="1.0" encoding="iso-8859-1" ?> <production> <productiondate>2011-09-18</productiondate> <updated>2011-09-19 13:03:00</updated> <section> <header>September 2011</header> <production> <header>Profit</header> <prodvalue>1451</prodvalue> <plandiff>-20</plandiff> </production> <production> <header>Hours</header> <prodvalue>1384</prodvalue> <plandiff>-55</plandiff> </production> <production> <header>Cost</header> <prodvalue>1203</prodvalue> <plandiff>-147</plandiff> </production> </section> <section> <header>Development</header> <production> <header>KA2</header> <prodvalue>0.0</prodvalue> <plandiff>-1.7</plandiff> </production> <production> <header>KA3</header> <prodvalue>1.2</prodvalue> <plandiff>-0.4</plandiff> </production> <production> <header>KK2</header> <prodvalue>10.8</prodvalue> <plandiff>-0.4</plandiff> </production> <production> <header>KK3</header> <prodvalue>13.3</prodvalue> <plandiff>-1.2</plandiff> </production> <production> <header>KK4</header> <prodvalue>13.9</prodvalue> <plandiff>-1.5</plandiff> </production> <production> <header>KS</header> <prodvalue>1.7</prodvalue> <plandiff>1.7</plandiff> </production> <production> <header>SA</header> <prodvalue>0.0</prodvalue> <plandiff>0.0</plandiff> </production> <production> <header>SK</header> <prodvalue>12.3</prodvalue> <plandiff>1.3</plandiff> </production> <production> <header>MK3</header> <prodvalue>11.1</prodvalue> <plandiff>0.6</plandiff> </production> <production> <header>BUV</header> <prodvalue>11.3</prodvalue> <plandiff>0.4</plandiff> </production> <production> <header>ANR</header> <prodvalue>8.2</prodvalue> <plandiff>2.4</plandiff> </production> </section> <section> <header>Ores</header> <production> <header>Sweden</header> <prodvalue>72.6</prodvalue> <plandiff>-3.3</plandiff> </production> <production> <header>Norway</header> <prodvalue>56.5</prodvalue> <plandiff>7.3</plandiff> </production> </section> <section> <header>Train</header> <production> <header>Sweden</header> <prodvalue>6</prodvalue> <plandiff>-4</plandiff> </production> <production> <header>Norway</header> <prodvalue>4</prodvalue> <plandiff>-1</plandiff> </production> </section> </production>
-
15 Feb 2012 3:43 AM #18
The hasMany associations keep giving only one result for the child data for XML. Isn't this issue still solved with ST 1.1? Using all the ideas given here, I get only one association data.
Swarnendu
Co-founder & Lead Architect @ Innofied
------------------
I blog at http://www.swarnendude.com
-
20 Mar 2012 2:12 PM #19
Thank you for reporting this bug. We will make it our priority to review this report.
Similar Threads
-
Nested Xml with associations?
By kaine in forum Sencha Touch 1.x: DiscussionReplies: 3Last Post: 15 Feb 2012, 3:46 AM -
[FIXED-583] nested xml / complex xml, cant get associations to work
By Nostromo in forum Sencha Touch 1.x: DiscussionReplies: 2Last Post: 19 Nov 2010, 7:39 AM -
[FIXED][2.x] File upload and XML response not work together
By Evolic in forum Ext 2.x: BugsReplies: 1Last Post: 5 May 2009, 8:54 AM -
Nested View Objects/Nested Xml collections
By dwebsubmit in forum Ext 1.x: Help & DiscussionReplies: 10Last Post: 11 Oct 2007, 2:30 PM


Reply With Quote
