1 <div class="body-wrap" xmlns:ext="http://www.extjs.com"><div class="top-tools"><a class="inner-link" href="#Ext.data.JsonWriter-props"><img src="resources/images/default/s.gif" class="item-icon icon-prop">Properties</a> <a class="inner-link" href="#Ext.data.JsonWriter-methods"><img src="resources/images/default/s.gif" class="item-icon icon-method">Methods</a> <a class="inner-link" href="#Ext.data.JsonWriter-events"><img src="resources/images/default/s.gif" class="item-icon icon-event">Events</a> <a class="inner-link" href="#Ext.data.JsonWriter-configs"><img src="resources/images/default/s.gif" class="item-icon icon-config">Config Options</a> <a class="bookmark" href="../docs/?class=Ext.data.JsonWriter"><img src="resources/images/default/s.gif" class="item-icon icon-fav">Direct Link</a> </div><div class="inheritance res-block"><pre class="res-block-inner"><a href="output/Ext.data.DataWriter.html" ext:member="" ext:cls="Ext.data.DataWriter">DataWriter</a>
2 <img src="resources/elbow-end.gif">JsonWriter</pre></div><h1>Class <a href="source/JsonWriter.html#cls-Ext.data.JsonWriter">Ext.data.JsonWriter</a></h1><table cellspacing="0"><tr><td class="label">Package:</td><td class="hd-info">Ext.data</td></tr><tr><td class="label">Defined In:</td><td class="hd-info"><a href="source/JsonWriter.html#cls-Ext.data.JsonWriter">JsonWriter.js</a></td></tr><tr><td class="label">Class:</td><td class="hd-info"><a href="source/JsonWriter.html#cls-Ext.data.JsonWriter">JsonWriter</a></td></tr><tr><td class="label">Extends:</td><td class="hd-info"><a href="output/Ext.data.DataWriter.html" ext:cls="Ext.data.DataWriter" ext:member="">DataWriter</a></td></tr></table><div class="description">DataWriter extension for writing an array or single <a href="output/Ext.data.Record.html" ext:cls="Ext.data.Record">Ext.data.Record</a> object(s) in preparation for executing a remote CRUD action.</div><div class="hr"></div><a id="Ext.data.JsonWriter-configs"></a><h2>Config Options</h2><table cellspacing="0" class="member-table"><tbody><tr><th colspan="2" class="sig-header">Config Options</th><th class="msource-header">Defined By</th></tr><tr class="config-row inherited"><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.data.DataWriter-createRecord"></a><b><a href="source/DataWriter.html#cfg-Ext.data.DataWriter-createRecord">createRecord</a></b> : Function<div class="mdesc">Abstract method that should be implemented in all subclasses
3 (e.g.: <a href="output/Ext.data.JsonWriter.html#Ext.data.JsonWriter-createRecord" ext:member="createRecord" ext:cls="Ext.data.JsonWriter">JsonWriter.createRecord</a>)</div></td><td class="msource"><a href="output/Ext.data.DataWriter.html#createRecord" ext:member="#createRecord" ext:cls="Ext.data.DataWriter">DataWriter</a></td></tr><tr class="config-row inherited"><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.data.DataWriter-destroyRecord"></a><b><a href="source/DataWriter.html#cfg-Ext.data.DataWriter-destroyRecord">destroyRecord</a></b> : Function<div class="mdesc">Abstract method that should be implemented in all subclasses
4 (e.g.: <a href="output/Ext.data.JsonWriter.html#Ext.data.JsonWriter-destroyRecord" ext:member="destroyRecord" ext:cls="Ext.data.JsonWriter">JsonWriter.destroyRecord</a>)</div></td><td class="msource"><a href="output/Ext.data.DataWriter.html#destroyRecord" ext:member="#destroyRecord" ext:cls="Ext.data.DataWriter">DataWriter</a></td></tr><tr class="config-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.data.JsonWriter-encode"></a><b><a href="source/JsonWriter.html#cfg-Ext.data.JsonWriter-encode">encode</a></b> : Boolean<div class="mdesc"><div class="short">true to JSON encode the
5 hashed data into a standard HTTP parameter named after this
6 Reader's meta.root property which...</div><div class="long"><p><tt>true</tt> to <a href="output/Ext.util.JSON.html#Ext.util.JSON-encode" ext:member="encode" ext:cls="Ext.util.JSON">JSON encode</a> the
7 <a href="output/Ext.data.DataWriter.html#Ext.data.DataWriter-toHash" ext:member="toHash" ext:cls="Ext.data.DataWriter">hashed data</a> into a standard HTTP parameter named after this
8 Reader's <code>meta.root</code> property which, by default is imported from the associated Reader. Defaults to <tt>true</tt>.</p>
9 <p>If set to <code>false</code>, the hashed data is <a href="output/Ext.util.JSON.html#Ext.util.JSON-encode" ext:member="encode" ext:cls="Ext.util.JSON">JSON encoded</a>, along with
10 the associated <a href="output/Ext.data.Store.html" ext:cls="Ext.data.Store">Ext.data.Store</a>'s <a href="output/Ext.data.Store.html#Ext.data.Store-baseParams" ext:member="baseParams" ext:cls="Ext.data.Store">baseParams</a>, into the POST body.</p>
11 <p>When using <a href="output/Ext.data.DirectProxy.html" ext:cls="Ext.data.DirectProxy">Ext.data.DirectProxy</a>, set this to <tt>false</tt> since Ext.Direct.JsonProvider will perform
12 its own json-encoding. In addition, if you're using <a href="output/Ext.data.HttpProxy.html" ext:cls="Ext.data.HttpProxy">Ext.data.HttpProxy</a>, setting to <tt>false</tt>
13 will cause HttpProxy to transmit data using the <b>jsonData</b> configuration-params of <a href="output/Ext.Ajax.html#Ext.Ajax-request" ext:member="request" ext:cls="Ext.Ajax">Ext.Ajax.request</a>
14 instead of <b>params</b>.</p>
15 <p>When using a <a href="output/Ext.data.Store.html#Ext.data.Store-restful" ext:member="restful" ext:cls="Ext.data.Store">Ext.data.Store.restful</a> Store, some serverside frameworks are
16 tuned to expect data through the jsonData mechanism. In those cases, one will want to set <b>encode: <tt>false</tt></b>, as in
17 let the lower-level connection object (eg: Ext.Ajax) do the encoding.</p></div></div></td><td class="msource">JsonWriter</td></tr><tr class="config-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.data.JsonWriter-encodeDelete"></a><b><a href="source/JsonWriter.html#cfg-Ext.data.JsonWriter-encodeDelete">encodeDelete</a></b> : Boolean<div class="mdesc"><div class="short">False to send only the id to the server on delete, true to encode it in an object
18 literal, eg: {id: 1} Defaults to fa...</div><div class="long">False to send only the id to the server on delete, true to encode it in an object
19 literal, eg: <pre><code>{id: 1}</code></pre> Defaults to <tt>false</tt></div></div></td><td class="msource">JsonWriter</td></tr><tr class="config-row expandable inherited"><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.data.DataWriter-listful"></a><b><a href="source/DataWriter.html#cfg-Ext.data.DataWriter-listful">listful</a></b> : Boolean<div class="mdesc"><div class="short">false by default. Set true to have the DataWriter always write HTTP params as a list,
20 even when acting upon a single...</div><div class="long"><tt>false</tt> by default. Set <tt>true</tt> to have the DataWriter <b>always</b> write HTTP params as a list,
21 even when acting upon a single record.</div></div></td><td class="msource"><a href="output/Ext.data.DataWriter.html#listful" ext:member="#listful" ext:cls="Ext.data.DataWriter">DataWriter</a></td></tr><tr class="config-row inherited"><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.data.DataWriter-updateRecord"></a><b><a href="source/DataWriter.html#cfg-Ext.data.DataWriter-updateRecord">updateRecord</a></b> : Function<div class="mdesc">Abstract method that should be implemented in all subclasses
22 (e.g.: <a href="output/Ext.data.JsonWriter.html#Ext.data.JsonWriter-updateRecord" ext:member="updateRecord" ext:cls="Ext.data.JsonWriter">JsonWriter.updateRecord</a></div></td><td class="msource"><a href="output/Ext.data.DataWriter.html#updateRecord" ext:member="#updateRecord" ext:cls="Ext.data.DataWriter">DataWriter</a></td></tr><tr class="config-row expandable inherited"><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.data.DataWriter-writeAllFields"></a><b><a href="source/DataWriter.html#cfg-Ext.data.DataWriter-writeAllFields">writeAllFields</a></b> : Boolean<div class="mdesc"><div class="short">false by default. Set true to have DataWriter return ALL fields of a modified
23 record -- not just those that changed....</div><div class="long"><tt>false</tt> by default. Set <tt>true</tt> to have DataWriter return ALL fields of a modified
24 record -- not just those that changed.
25 <tt>false</tt> to have DataWriter only request modified fields from a record.</div></div></td><td class="msource"><a href="output/Ext.data.DataWriter.html#writeAllFields" ext:member="#writeAllFields" ext:cls="Ext.data.DataWriter">DataWriter</a></td></tr></tbody></table><a id="Ext.data.JsonWriter-props"></a><h2>Public Properties</h2><div class="no-members">This class has no public properties.</div><a id="Ext.data.JsonWriter-methods"></a><h2>Public Methods</h2><table cellspacing="0" class="member-table"><tbody><tr><th colspan="2" class="sig-header">Method</th><th class="msource-header">Defined By</th></tr><tr class="method-row expandable inherited"><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.data.DataWriter-apply"></a><b><a href="source/DataWriter.html#method-Ext.data.DataWriter-apply">apply</a></b>( <code>Object params</code>, <code>Object baseParams</code>, <code>String action</code>, <code>Record/Record[] rs</code> )
27 void<div class="mdesc"><div class="short">Compiles a Store recordset into a data-format defined by an extension such as Ext.data.JsonWriter or Ext.data.XmlWrit...</div><div class="long">Compiles a Store recordset into a data-format defined by an extension such as <a href="output/Ext.data.JsonWriter.html" ext:cls="Ext.data.JsonWriter">Ext.data.JsonWriter</a> or <a href="output/Ext.data.XmlWriter.html" ext:cls="Ext.data.XmlWriter">Ext.data.XmlWriter</a> in preparation for a <a href="output/Ext.data.Api.html#Ext.data.Api-actions" ext:member="actions" ext:cls="Ext.data.Api">server-write action</a>. The first two params are similar similar in nature to <a href="output/Ext.html#Ext-apply" ext:member="apply" ext:cls="Ext">Ext.apply</a>,
28 Where the first parameter is the <i>receiver</i> of paramaters and the second, baseParams, <i>the source</i>.<div class="mdetail-params"><strong>Parameters:</strong><ul><li><code>params</code> : Object<div class="sub-desc">The request-params receiver.</div></li><li><code>baseParams</code> : Object<div class="sub-desc">as defined by <a href="output/Ext.data.Store.html#Ext.data.Store-baseParams" ext:member="baseParams" ext:cls="Ext.data.Store">Ext.data.Store.baseParams</a>. The baseParms must be encoded by the extending class, eg: <a href="output/Ext.data.JsonWriter.html" ext:cls="Ext.data.JsonWriter">Ext.data.JsonWriter</a>, <a href="output/Ext.data.XmlWriter.html" ext:cls="Ext.data.XmlWriter">Ext.data.XmlWriter</a>.</div></li><li><code>action</code> : String<div class="sub-desc">[<a href="output/Ext.data.Api.html#Ext.data.Api-actions" ext:member="actions" ext:cls="Ext.data.Api">create|update|destroy</a>]</div></li><li><code>rs</code> : Record/Record[]<div class="sub-desc">The recordset to write, the subject(s) of the write action.</div></li></ul><strong>Returns:</strong><ul><li>void</li></ul></div></div></div></td><td class="msource"><a href="output/Ext.data.DataWriter.html#apply" ext:member="#apply" ext:cls="Ext.data.DataWriter">DataWriter</a></td></tr><tr class="method-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.data.JsonWriter-createRecord"></a><b><a href="source/JsonWriter.html#method-Ext.data.JsonWriter-createRecord">createRecord</a></b>( <code>Ext.data.Record rec</code> )
30 Object<div class="mdesc"><div class="short">Implements abstract Ext.data.DataWriter#createRecord</div><div class="long">Implements abstract Ext.data.DataWriter#createRecord<div class="mdetail-params"><strong>Parameters:</strong><ul><li><code>rec</code> : Ext.data.Record<div class="sub-desc"></div></li></ul><strong>Returns:</strong><ul><li><code>Object</code><div class="sub-desc"></div></li></ul></div></div></div></td><td class="msource">JsonWriter</td></tr><tr class="method-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.data.JsonWriter-destroyRecord"></a><b><a href="source/JsonWriter.html#method-Ext.data.JsonWriter-destroyRecord">destroyRecord</a></b>( <code>Ext.data.Record rec</code> )
32 Object<div class="mdesc"><div class="short">Implements abstract Ext.data.DataWriter#destroyRecord</div><div class="long">Implements abstract Ext.data.DataWriter#destroyRecord<div class="mdetail-params"><strong>Parameters:</strong><ul><li><code>rec</code> : Ext.data.Record<div class="sub-desc"></div></li></ul><strong>Returns:</strong><ul><li><code>Object</code><div class="sub-desc"></div></li></ul></div></div></div></td><td class="msource">JsonWriter</td></tr><tr class="method-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.data.JsonWriter-render"></a><b><a href="source/JsonWriter.html#method-Ext.data.JsonWriter-render">render</a></b>( <code>Object Ajax</code>, <code>Object baseParams</code>, <code>Object/Object[] data</code> )
34 void<div class="mdesc"><div class="short">This method should not need to be called by application code, however it may be useful on occasion to
35 override it, or...</div><div class="long"><p>This method should not need to be called by application code, however it may be useful on occasion to
36 override it, or augment it with an <a href="output/Function.html#Function-createInterceptor" ext:member="createInterceptor" ext:cls="Function">interceptor</a> or <a href="output/Function.html#Function-createSequence" ext:member="createSequence" ext:cls="Function">sequence</a>.</p>
37 <p>The provided implementation encodes the serialized data representing the Store's modified Records into the Ajax request's
38 <code>params</code> according to the <code><a href="output/Ext.data.JsonWriter.html#Ext.data.JsonWriter-encode" ext:member="encode" ext:cls="Ext.data.JsonWriter">encode</a></code> setting.</p><div class="mdetail-params"><strong>Parameters:</strong><ul><li><code>Ajax</code> : Object<div class="sub-desc">request params object to write into.</div></li><li><code>baseParams</code> : Object<div class="sub-desc">as defined by <a href="output/Ext.data.Store.html#Ext.data.Store-baseParams" ext:member="baseParams" ext:cls="Ext.data.Store">Ext.data.Store.baseParams</a>. The baseParms must be encoded by the extending class, eg: <a href="output/Ext.data.JsonWriter.html" ext:cls="Ext.data.JsonWriter">Ext.data.JsonWriter</a>, <a href="output/Ext.data.XmlWriter.html" ext:cls="Ext.data.XmlWriter">Ext.data.XmlWriter</a>.</div></li><li><code>data</code> : Object/Object[]<div class="sub-desc">Data object representing the serialized modified records from the Store. May be either a single object,
39 or an Array of objects - user implementations must handle both cases.</div></li></ul><strong>Returns:</strong><ul><li>void</li></ul></div></div></div></td><td class="msource">JsonWriter</td></tr><tr class="method-row expandable inherited"><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.data.DataWriter-toArray"></a><b><a href="source/DataWriter.html#method-Ext.data.DataWriter-toArray">toArray</a></b>( <code>Hash data</code> )
41 [Object]<div class="mdesc"><div class="short">Converts a Hashed Ext.data.Record to fields-array array suitable
42 for encoding to xml via XTemplate, eg:
43 &lt;tpl for="...</div><div class="long">Converts a <a href="output/Ext.data.DataWriter.html#Ext.data.DataWriter-toHash" ext:member="toHash" ext:cls="Ext.data.DataWriter">Hashed</a> <a href="output/Ext.data.Record.html" ext:cls="Ext.data.Record">Ext.data.Record</a> to fields-array array suitable
44 for encoding to xml via XTemplate, eg:
45 <code><pre><tpl <b>for</b>=<em>"."</em>><{name}>{value}</{name}</tpl></pre></code>
46 eg, <b>non-phantom</b>:
47 <code><pre>{id: 1, first: <em>'foo'</em>, last: <em>'bar'</em>} --> [{name: <em>'id'</em>, value: 1}, {name: <em>'first'</em>, value: <em>'foo'</em>}, {name: <em>'last'</em>, value: <em>'bar'</em>}]</pre></code>
48 <a href="output/Ext.data.Record.html#Ext.data.Record-phantom" ext:member="phantom" ext:cls="Ext.data.Record">Phantom</a> records will have had their idProperty omitted in <a href="output/Ext.data.DataWriter.html#Ext.data.DataWriter-toHash" ext:member="toHash" ext:cls="Ext.data.DataWriter">toHash</a> if determined to be auto-generated.
49 Non AUTOINCREMENT pks should have been protected.<div class="mdetail-params"><strong>Parameters:</strong><ul><li><code>data</code> : Hash<div class="sub-desc">Hashed by Ext.data.DataWriter#toHash</div></li></ul><strong>Returns:</strong><ul><li><code>[Object]</code><div class="sub-desc">Array of attribute-objects.</div></li></ul></div></div></div></td><td class="msource"><a href="output/Ext.data.DataWriter.html#toArray" ext:member="#toArray" ext:cls="Ext.data.DataWriter">DataWriter</a></td></tr><tr class="method-row expandable inherited"><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.data.DataWriter-toHash"></a><b><a href="source/DataWriter.html#method-Ext.data.DataWriter-toHash">toHash</a></b>( <code>Ext.data.Record rec</code>, <code>Object config</code> )
51 Object<div class="mdesc"><div class="short">Converts a Record to a hash, taking into account the state of the Ext.data.Record along with configuration properties...</div><div class="long">Converts a Record to a hash, taking into account the state of the Ext.data.Record along with configuration properties
52 related to its rendering, such as <a href="output/Ext.data.DataWriter.html#Ext.data.DataWriter-writeAllFields" ext:member="writeAllFields" ext:cls="Ext.data.DataWriter">writeAllFields</a>, <a href="output/Ext.data.Record.html#Ext.data.Record-phantom" ext:member="phantom" ext:cls="Ext.data.Record">phantom</a>, <a href="output/Ext.data.Record.html#Ext.data.Record-getChanges" ext:member="getChanges" ext:cls="Ext.data.Record">getChanges</a> and
53 <a href="output/Ext.data.DataReader.html#Ext.data.DataReader-idProperty" ext:member="idProperty" ext:cls="Ext.data.DataReader">idProperty</a><div class="mdetail-params"><strong>Parameters:</strong><ul><li><code>rec</code> : Ext.data.Record<div class="sub-desc">The Record from which to create a hash.</div></li><li><code>config</code> : Object<div class="sub-desc"><b>NOT YET IMPLEMENTED</b>. Will implement an exlude/only configuration for fine-control over which fields do/don't get rendered.</div></li></ul><strong>Returns:</strong><ul><li><code>Object</code><div class="sub-desc"></div></li></ul></div></div></div></td><td class="msource"><a href="output/Ext.data.DataWriter.html#toHash" ext:member="#toHash" ext:cls="Ext.data.DataWriter">DataWriter</a></td></tr><tr class="method-row expandable "><td class="micon"><a href="#expand" class="exi"> </a></td><td class="sig"><a id="Ext.data.JsonWriter-updateRecord"></a><b><a href="source/JsonWriter.html#method-Ext.data.JsonWriter-updateRecord">updateRecord</a></b>( <code>Ext.data.Record rec</code> )
55 Object<div class="mdesc"><div class="short">Implements abstract Ext.data.DataWriter#updateRecord</div><div class="long">Implements abstract Ext.data.DataWriter#updateRecord<div class="mdetail-params"><strong>Parameters:</strong><ul><li><code>rec</code> : Ext.data.Record<div class="sub-desc"></div></li></ul><strong>Returns:</strong><ul><li><code>Object</code><div class="sub-desc"></div></li></ul></div></div></div></td><td class="msource">JsonWriter</td></tr></tbody></table><a id="Ext.data.JsonWriter-events"></a><h2>Public Events</h2><div class="no-members">This class has no public events.</div></div>