Note that there are some explanatory texts on larger screens.

plurals
  1. POExtJS 4: Write nested XML with model associations
    primarykey
    data
    text
    <p>I'm trying to write nested XML data via model associations but I can't go ahead.</p> <p>First of all the XML:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;card&gt; &lt;generalData&gt; &lt;name&gt;A card&lt;/name&gt; &lt;description&gt;That's a description&lt;/description&gt; &lt;/generalData&gt; &lt;specificData&gt; &lt;number&gt;100&lt;/number&gt; &lt;type&gt;int&lt;/type&gt; &lt;/specificData&gt; &lt;otherStuff&gt; &lt;note&gt;Those notes...&lt;/note&gt; &lt;/otherStuff&gt; &lt;/card&gt; </code></pre> <p>Here's the code of models:</p> <pre class="lang-js prettyprint-override"><code>Ext.define ('generalData', { extend: 'Ext.data.Model' , fields: ['name', 'description'] }); Ext.define ('specificData', { extend: 'Ext.data.Model' , fields: ['number', 'type'] }); Ext.define ('otherStuff', { extend: 'Ext.data.Model' , fields: ['note'] }); Ext.define ('Card', { extend: 'Ext.data.Model' , requires: ['generalData', 'specificData', 'otherStuff'] , hasOne: [{ name: 'generalData' , model: 'generalData' , getterName: 'getGeneralData' , associationKey: 'generalData' , reader: { type: 'xml' , root: 'generalData' , record: 'generalData' } , writer: { type: 'xml' , documentRoot: 'generalData' , record: 'generalData' } } , { name: 'specificData' , model: 'specificData' , getterName: 'getSpecificData' , associationKey: 'specificData' , reader: { type: 'xml' , root: 'specificData' , record: 'specificData' } , writer: { type: 'xml' , documentRoot: 'specificData' , record: 'specificData' } } , { name: 'otherStuff' , model: 'otherStuff' , getterName: 'getOtherStuff' , associationKey: 'otherStuff' , reader: { type: 'xml' , root: 'otherStuff' , record: 'otherStuff' } , writer: { type: 'xml' , documentRoot: 'otherStuff' , record: 'otherStuff' } }] , proxy: { type: 'ajax' , url: '/card' , reader: { type: 'xml' , record: 'card' , root: 'card' } , writer: { type: 'xml' , documentRoot: 'card' , record: 'card' , header: '&lt;?xml version="1.0" encoding="utf-8"?&gt;' } } }); </code></pre> <p>As you can see, each model has his reader and writer (this last one is really needed?).</p> <p>Here I retrieve data and I try to send it back to the server.</p> <pre class="lang-js prettyprint-override"><code>Card.load (1, { success: function (card) { console.log (card); var gd = card.getGeneralData (function (data) { console.log (data.get ('name')); data.set ('name', 'Another card'); }); card.save (); } }); </code></pre> <p>When 'success' function is called, I've all the XML I requested and 'A card' is written on the console. Then, I try to change the name of the card in 'Another card' and send the data back with <em>card.save ()</em>. At this point, I got three kind of problems:</p> <p>1) The request paylod (data sent to the server) isn't the XML I got on the previous request. In fact, it has the following structure:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;card&gt; &lt;card&gt; &lt;id&gt;&lt;/id&gt; &lt;/card&gt; &lt;/card&gt; </code></pre> <p>I got this structure because of the writer: empty with two equal elements and a new element ('id') I didn't specify nowhere. So, the first question is: <strong>how can I add a single documentRoot or record element to the data I've to send?</strong></p> <p>2) The second point is: <strong>where's my data? Why the sent XML is empty? Am I doing right the model saving process?</strong></p> <p>3) And, in the end, the third problem: the <em>Content-Type</em> of the request is <strong>text/xml</strong>. So, <strong>how can I change it into application/xml?</strong></p> <p>Model associations are ok with reading but I can't really understand how they works with writing. <strong>What I want is just read the XML data, modify some fields and then send it back again, everything with the XML format.</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload