Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / api / Ext.data.writer.Json.html
1 <!DOCTYPE html><html><head><title>Ext.data.writer.Json | Ext JS 4.0 Documentation</title><script type="text/javascript" src="../ext-all.js"></script><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../scrollbars.css" type="text/css"><link rel="stylesheet" href="../docs.css" type="text/css"><link id="styleCss" rel="stylesheet" href="../style.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script><link rel="stylesheet" href="../prettify.css" type="text/css"><!-- link(rel: 'stylesheet', href: req.baseURL + '/css/ext4.css', type: 'text/css')--><link rel="shortcut icon" type="image/ico" href="../favicon.ico"><!--[if IE]>
2 <style type="text/css">.head-band { display: none; }
3 .header { border: 0; top: 0; left: 0px; background: url(../header.gif) repeat-x; }
4 .doc-tab .members .member a.more { background-color: #efefef; }
5 </style><link rel="stylesheet" href="/new/css/ie.css" type="text/css"><![endif]-->
6 </head><body id="ext-body" class="iScroll"><div id="notice" class="notice">For up to date documentation and features, visit 
7 <a href="http://docs.sencha.com/ext-js/4-0">http://docs.sencha.com/ext-js/4-0</a></div><div class="wrapper"><div class="head-band"></div><div class="header"><h2><a href="../index.html">Sencha Documentation</a></h2></div><div id="search"><form><input type="text" placeholder="Search" id="search-field" autocomplete="off" name="q"></form><div id="search-box"></div></div><div id="treePanel"></div><div id="container"><script type="text/javascript">
8
9     req = {
10         liveURL: '.',
11         standAloneMode: true,
12         origDocClass: 'Ext.data.writer.Json',
13         docClass: 'Ext.data.writer.Json',
14         docReq: 'Ext.data.writer.Json',
15         version: '4.0',
16         baseURL: '.',
17         baseDocURL: '.',
18         baseProdURL: '.'
19     };
20
21     clsInfo = {};
22
23
24
25 </script>
26
27 <script type="text/javascript" src="../search.js"></script>
28 <!--script type="text/javascript" src="/new/javascripts/app/examples.js"></script-->
29 <script type="text/javascript" src="../class_tree.js"></script>
30 <script type="text/javascript" src="../class_doc.js"></script>
31 <script type="text/javascript">
32     req.source = 'Json2.html#Ext-data.writer.Json';
33     clsInfo = {"methods":["Json","getRecordData","write"],"cfgs":["allowSingle","encode","nameProperty","root","writeAllFields"],"properties":[],"events":[],"subclasses":[]};
34     Ext.onReady(function() {
35         Ext.create('Docs.classPanel');
36     });
37 </script><div id="top-block" class="top-block"><h1 id="clsTitle" class="cls"><a href="../source/Json2.html#Ext-data.writer.Json" target="_blank">Ext.data.writer.Json</a></h1></div><div id="docContent"><div id="doc-overview-content"><div class="lft"><pre class="subclasses"><h4>Hierarchy</h4><div class="subclass f"><a href="Ext.data.writer.Writer.html" rel="Ext.data.writer.Writer" class="cls docClass">Ext.data.writer.Writer</a><div class="subclass"><strong>Ext.data.writer.Json</strong></div></div></pre>
38 <div class="members"><div class="m-cfgs"><div class="definedBy">Defined By</div><a name="configs"></a><h3 class="cfg p">Config Options</h3><h4 class="cfgGroup">Other Configs</h4><div id="config-allowSingle" class="member f ni"><a href="Ext.data.writer.Json.html#config-allowSingle" rel="config-allowSingle" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.data.writer.Json.html" class="definedIn docClass">Ext.data.writer.Json</a><br/><a href="../source/Json2.html#Ext-data.writer.Json-cfg-allowSingle" class="viewSource">view source</a></div><a name="allowSingle"></a><a name="config-allowSingle"></a><a href="Ext.data.writer.Json.html#" rel="config-allowSingle" class="cls expand">allowSingle</a><span> : Boolean</span></div><div class="description"><div class="short">False to ensure that records are always wrapped in an array, even if there is only
39 one record being sent. When there ...</div><div class="long"><p>False to ensure that records are always wrapped in an array, even if there is only
40 one record being sent. When there is more than one record, they will always be encoded into an array.
41 Defaults to <tt>true</tt>. Example:</p>
42
43 <pre><code>// with allowSingle: true
44 "root": {
45     "first": "Mark",
46     "last": "Corrigan"
47 }
48
49 // with allowSingle: false
50 "root": [{
51     "first": "Mark",
52     "last": "Corrigan"
53 }]
54 </code></pre>
55
56 </div></div></div><div id="config-encode" class="member ni"><a href="Ext.data.writer.Json.html#config-encode" rel="config-encode" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.data.writer.Json.html" class="definedIn docClass">Ext.data.writer.Json</a><br/><a href="../source/Json2.html#Ext-data.writer.Json-cfg-encode" class="viewSource">view source</a></div><a name="encode"></a><a name="config-encode"></a><a href="Ext.data.writer.Json.html#" rel="config-encode" class="cls expand">encode</a><span> : Boolean</span></div><div class="description"><div class="short">True to use Ext.encode() on the data before sending. Defaults to false.
57 The encode option should only be set to true ...</div><div class="long"><p>True to use Ext.encode() on the data before sending. Defaults to <tt>false</tt>.
58 The encode option should only be set to true when a <a href="Ext.data.writer.Json.html#root" rel="Ext.data.writer.Json#root" class="docClass">root</a> is defined, because the values will be
59 sent as part of the request parameters as opposed to a raw post. The root will be the name of the parameter
60 sent to the server.</p>
61 </div></div></div><div id="config-nameProperty" class="member inherited"><a href="Ext.data.writer.Json.html#config-nameProperty" rel="config-nameProperty" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.data.writer.Writer.html" class="definedIn docClass">Ext.data.writer.Writer</a><br/><a href="../source/Writer.html#Ext-data.writer.Writer-cfg-nameProperty" class="viewSource">view source</a></div><a name="nameProperty"></a><a name="config-nameProperty"></a><a href="Ext.data.writer.Json.html#" rel="config-nameProperty" class="cls expand">nameProperty</a><span> : String</span></div><div class="description"><div class="short">This property is used to read the key for each value that will be sent to the server.
62 For example:
63
64 Ext.define('Perso...</div><div class="long"><p>This property is used to read the key for each value that will be sent to the server.
65 For example:</p>
66
67 <pre><code>Ext.define('Person', {
68     extend: 'Ext.data.Model',
69     fields: [{
70         name: 'first',
71         mapping: 'firstName'
72     }, {
73         name: 'last',
74         mapping: 'lastName'
75     }, {
76         name: 'age'
77     }]
78 });
79 new Ext.data.writer.Writer({
80     writeAllFields: true,
81     nameProperty: 'mapping'
82 });
83
84 // This will be sent to the server
85 {
86     firstName: 'first name value',
87     lastName: 'last name value',
88     age: 1
89 }
90
91 </code></pre>
92
93
94 <p>Defaults to <tt>name</tt>. If the value is not present, the field name will always be used.</p>
95 </div></div></div><div id="config-root" class="member ni"><a href="Ext.data.writer.Json.html#config-root" rel="config-root" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.data.writer.Json.html" class="definedIn docClass">Ext.data.writer.Json</a><br/><a href="../source/Json2.html#Ext-data.writer.Json-cfg-root" class="viewSource">view source</a></div><a name="root"></a><a name="config-root"></a><a href="Ext.data.writer.Json.html#" rel="config-root" class="cls expand">root</a><span> : String</span></div><div class="description"><div class="short">The key under which the records in this Writer will be placed. Defaults to undefined.
96 Example generated request, usin...</div><div class="long"><p>The key under which the records in this Writer will be placed. Defaults to <tt>undefined</tt>.
97 Example generated request, using root: 'records':</p>
98
99 <pre><code>{'records': [{name: 'my record'}, {name: 'another record'}]}
100 </code></pre>
101
102 </div></div></div><div id="config-writeAllFields" class="member inherited"><a href="Ext.data.writer.Json.html#config-writeAllFields" rel="config-writeAllFields" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.data.writer.Writer.html" class="definedIn docClass">Ext.data.writer.Writer</a><br/><a href="../source/Writer.html#Ext-data.writer.Writer-cfg-writeAllFields" class="viewSource">view source</a></div><a name="writeAllFields"></a><a name="config-writeAllFields"></a><a href="Ext.data.writer.Json.html#" rel="config-writeAllFields" class="cls expand">writeAllFields</a><span> : Boolean</span></div><div class="description"><div class="short">True to write all fields from the record to the server. If set to false it
103 will only send the fields that were modifi...</div><div class="long"><p>True to write all fields from the record to the server. If set to false it
104 will only send the fields that were modified. Defaults to <tt>true</tt>. Note that any fields that have
105 <a href="Ext.data.Field.html#persist" rel="Ext.data.Field#persist" class="docClass">Ext.data.Field.persist</a> set to false will still be ignored.</p>
106 </div></div></div></div><div class="m-methods"><a name="methods"></a><div class="definedBy">Defined By</div><h3 class="mth p">Methods</h3><div id="method-Json" class="member f inherited"><a href="Ext.data.writer.Json.html#method-Json" rel="method-Json" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.data.writer.Writer.html" class="definedIn docClass">Ext.data.writer.Writer</a><br/><a href="../source/Writer.html#Ext-data.writer.Writer-method-constructor" class="viewSource">view source</a></div><a name="Json"></a><a name="method-Json"></a><a href="Ext.data.writer.Json.html#" rel="method-Json" class="cls expand">Json</a>(
107 <span class="pre">Object config</span>)
108  : void</div><div class="description"><div class="short"><p>&nbsp;</p></div><div class="long">
109 <h3 class="pa">Parameters</h3><ul><li><span class="pre">config</span> : Object<div class="sub-desc"><p>Optional config object</p>
110 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
111 </li></ul></div></div></div><div id="method-getRecordData" class="member inherited"><a href="Ext.data.writer.Json.html#method-getRecordData" rel="method-getRecordData" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.data.writer.Writer.html" class="definedIn docClass">Ext.data.writer.Writer</a><br/><a href="../source/Writer.html#Ext-data.writer.Writer-method-getRecordData" class="viewSource">view source</a></div><a name="getRecordData"></a><a name="method-getRecordData"></a><a href="Ext.data.writer.Json.html#" rel="method-getRecordData" class="cls expand">getRecordData</a>(
112 <span class="pre">Object record</span>)
113  : Object</div><div class="description"><div class="short">Formats the data for each record before sending it to the server. This
114 method should be overridden to format the data...</div><div class="long"><p>Formats the data for each record before sending it to the server. This
115 method should be overridden to format the data in a way that differs from the default.</p>
116 <h3 class="pa">Parameters</h3><ul><li><span class="pre">record</span> : Object<div class="sub-desc"><p>The record that we are writing to the server.</p>
117 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Object</span>&nbsp; &nbsp;<p>An object literal of name/value keys to be written to the server.
118 By default this method returns the data property on the record.</p>
119 </li></ul></div></div></div><div id="method-write" class="member inherited"><a href="Ext.data.writer.Json.html#method-write" rel="method-write" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.data.writer.Writer.html" class="definedIn docClass">Ext.data.writer.Writer</a><br/><a href="../source/Writer.html#Ext-data.writer.Writer-method-write" class="viewSource">view source</a></div><a name="write"></a><a name="method-write"></a><a href="Ext.data.writer.Json.html#" rel="method-write" class="cls expand">write</a>(
120 <span class="pre">Ext.data.Request request</span>)
121  : Ext.data.Request</div><div class="description"><div class="short"><p>Prepares a Proxy's <a href="Ext.data.Request.html" rel="Ext.data.Request" class="docClass">Ext.data.Request</a> object</p>
122 </div><div class="long"><p>Prepares a Proxy's <a href="Ext.data.Request.html" rel="Ext.data.Request" class="docClass">Ext.data.Request</a> object</p>
123 <h3 class="pa">Parameters</h3><ul><li><span class="pre">request</span> : Ext.data.Request<div class="sub-desc"><p>The request object</p>
124 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Ext.data.Request</span>&nbsp; &nbsp;<p>The modified request object</p>
125 </li></ul></div></div></div></div></div></div></div><div id="pageContent"></div></div></div></div></body></html>