Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / JsonWriter.html
1 <html>\r
2 <head>\r
3   <title>The source code</title>\r
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js"><div id="cls-Ext.data.JsonWriter"></div>/**
9  * @class Ext.data.JsonWriter
10  * @extends Ext.data.DataWriter
11  * DataWriter extension for writing an array or single {@link Ext.data.Record} object(s) in preparation for executing a remote CRUD action.
12  */
13 Ext.data.JsonWriter = function(config) {
14     Ext.data.JsonWriter.superclass.constructor.call(this, config);
15
16     // careful to respect "returnJson", renamed to "encode"
17     // TODO: remove after v3 final release
18     if (this.returnJson != undefined) {
19         this.encode = this.returnJson;
20     }
21 }
22 Ext.extend(Ext.data.JsonWriter, Ext.data.DataWriter, {
23     <div id="cfg-Ext.data.JsonWriter-returnJson"></div>/**
24      * @cfg {Boolean} returnJson <b>Deprecated.  Use {@link Ext.data.JsonWriter#encode} instead.
25      */
26     returnJson : undefined,
27     <div id="cfg-Ext.data.JsonWriter-encode"></div>/**
28      * @cfg {Boolean} encode <tt>true</tt> to {@link Ext.util.JSON#encode encode} the
29      * {@link Ext.data.DataWriter#toHash hashed data}. Defaults to <tt>true</tt>.  When using
30      * {@link Ext.data.DirectProxy}, set this to <tt>false</tt> since Ext.Direct.JsonProvider will perform
31      * its own json-encoding.  In addition, if you're using {@link Ext.data.HttpProxy}, setting to <tt>false</tt>
32      * will cause HttpProxy to transmit data using the <b>jsonData</b> configuration-params of {@link Ext.Ajax#request}
33      * instead of <b>params</b>.  When using a {@link Ext.data.Store#restful} Store, some serverside frameworks are
34      * tuned to expect data through the jsonData mechanism.  In those cases, one will want to set <b>encode: <tt>false</tt></b>
35      */
36     encode : true,
37
38     <div id="method-Ext.data.JsonWriter-render"></div>/**
39      * Final action of a write event.  Apply the written data-object to params.
40      * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
41      * @param {Record[]} rs
42      * @param {Object} http params
43      * @param {Object} data object populated according to DataReader meta-data "root" and "idProperty"
44      */
45     render : function(action, rs, params, data) {
46         Ext.apply(params, data);
47
48         if (this.encode === true) { // <-- @deprecated returnJson
49             if (Ext.isArray(rs) && data[this.meta.idProperty]) {
50                 params[this.meta.idProperty] = Ext.encode(params[this.meta.idProperty]);
51             }
52             params[this.meta.root] = Ext.encode(params[this.meta.root]);
53         }
54     },
55     <div id="method-Ext.data.JsonWriter-createRecord"></div>/**
56      * createRecord
57      * @protected
58      * @param {Ext.data.Record} rec
59      */
60     createRecord : function(rec) {
61        var data = this.toHash(rec);
62        delete data[this.meta.idProperty];
63        return data;
64     },
65     <div id="method-Ext.data.JsonWriter-updateRecord"></div>/**
66      * updateRecord
67      * @protected
68      * @param {Ext.data.Record} rec
69      */
70     updateRecord : function(rec) {
71         return this.toHash(rec);
72
73     },
74     <div id="method-Ext.data.JsonWriter-destroyRecord"></div>/**
75      * destroyRecord
76      * @protected
77      * @param {Ext.data.Record} rec
78      */
79     destroyRecord : function(rec) {
80         return rec.id;
81     }
82 });</pre>    \r
83 </body>\r
84 </html>