3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.data.JsonWriter
9 * @extends Ext.data.DataWriter
10 * DataWriter extension for writing an array or single {@link Ext.data.Record} object(s) in preparation for executing a remote CRUD action.
12 Ext.data.JsonWriter = function(config) {
13 Ext.data.JsonWriter.superclass.constructor.call(this, config);
14 // careful to respect "returnJson", renamed to "encode"
15 if (this.returnJson != undefined) {
16 this.encode = this.returnJson;
19 Ext.extend(Ext.data.JsonWriter, Ext.data.DataWriter, {
21 * @cfg {Boolean} returnJson <b>Deprecated. Use {@link Ext.data.JsonWriter#encode} instead.
23 returnJson : undefined,
25 * @cfg {Boolean} encode <tt>true</tt> to {@link Ext.util.JSON#encode encode} the
26 * {@link Ext.data.DataWriter#toHash hashed data}. Defaults to <tt>true</tt>. When using
27 * {@link Ext.data.DirectProxy}, set this to <tt>false</tt> since Ext.Direct.JsonProvider will perform
28 * its own json-encoding. In addition, if you're using {@link Ext.data.HttpProxy}, setting to <tt>false</tt>
29 * will cause HttpProxy to transmit data using the <b>jsonData</b> configuration-params of {@link Ext.Ajax#request}
30 * instead of <b>params</b>. When using a {@link Ext.data.Store#restful} Store, some serverside frameworks are
31 * tuned to expect data through the jsonData mechanism. In those cases, one will want to set <b>encode: <tt>false</tt></b>
36 * Final action of a write event. Apply the written data-object to params.
37 * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
38 * @param {Record[]} rs
39 * @param {Object} http params
40 * @param {Object} data object populated according to DataReader meta-data "root" and "idProperty"
42 render : function(action, rs, params, data) {
43 Ext.apply(params, data);
45 if (this.encode === true) { // <-- @deprecated returnJson
46 if (Ext.isArray(rs) && data[this.meta.idProperty]) {
47 params[this.meta.idProperty] = Ext.encode(params[this.meta.idProperty]);
49 params[this.meta.root] = Ext.encode(params[this.meta.root]);
55 * @param {Ext.data.Record} rec
57 createRecord : function(rec) {
58 return this.toHash(rec);
63 * @param {Ext.data.Record} rec
65 updateRecord : function(rec) {
66 return this.toHash(rec);
72 * @param {Ext.data.Record} rec
74 destroyRecord : function(rec) {