3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.data.JsonWriter"></div>/**
10 * @class Ext.data.JsonWriter
11 * @extends Ext.data.DataWriter
12 * DataWriter extension for writing an array or single {@link Ext.data.Record} object(s) in preparation for executing a remote CRUD action.
14 Ext.data.JsonWriter = Ext.extend(Ext.data.DataWriter, {
15 <div id="cfg-Ext.data.JsonWriter-encode"></div>/**
16 * @cfg {Boolean} encode <tt>true</tt> to {@link Ext.util.JSON#encode encode} the
17 * {@link Ext.data.DataWriter#toHash hashed data}. Defaults to <tt>true</tt>. When using
18 * {@link Ext.data.DirectProxy}, set this to <tt>false</tt> since Ext.Direct.JsonProvider will perform
19 * its own json-encoding. In addition, if you're using {@link Ext.data.HttpProxy}, setting to <tt>false</tt>
20 * will cause HttpProxy to transmit data using the <b>jsonData</b> configuration-params of {@link Ext.Ajax#request}
21 * instead of <b>params</b>. When using a {@link Ext.data.Store#restful} Store, some serverside frameworks are
22 * tuned to expect data through the jsonData mechanism. In those cases, one will want to set <b>encode: <tt>false</tt></b>, as in
23 * let the lower-level connection object (eg: Ext.Ajax) do the encoding.
26 <div id="cfg-Ext.data.JsonWriter-encodeDelete"></div>/**
27 * @cfg {Boolean} encodeDelete False to send only the id to the server on delete, true to encode it in an object
28 * literal, eg: <pre><code>
30 * </code></pre> Defaults to <tt>false</tt>
34 constructor : function(config){
35 Ext.data.JsonWriter.superclass.constructor.call(this, config);
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 {Object} http params-object to write-to.
41 * @param {Object} baseParams as defined by {@link Ext.data.Store#baseParams}. The baseParms must be encoded by the extending class, eg: {@link Ext.data.JsonWriter}, {@link Ext.data.XmlWriter}.
42 * @param {Object/Object[]} data Data-object representing compiled Store-recordset.
44 render : function(params, baseParams, data) {
45 if (this.encode === true) {
47 Ext.apply(params, baseParams);
48 params[this.meta.root] = Ext.encode(data);
50 // defer encoding for some other layer, probably in {@link Ext.Ajax#request}. Place everything into "jsonData" key.
51 var jdata = Ext.apply({}, baseParams);
52 jdata[this.meta.root] = data;
53 params.jsonData = jdata;
56 <div id="method-Ext.data.JsonWriter-createRecord"></div>/**
57 * Implements abstract Ext.data.DataWriter#createRecord
59 * @param {Ext.data.Record} rec
62 createRecord : function(rec) {
63 return this.toHash(rec);
65 <div id="method-Ext.data.JsonWriter-updateRecord"></div>/**
66 * Implements abstract Ext.data.DataWriter#updateRecord
68 * @param {Ext.data.Record} rec
71 updateRecord : function(rec) {
72 return this.toHash(rec);
75 <div id="method-Ext.data.JsonWriter-destroyRecord"></div>/**
76 * Implements abstract Ext.data.DataWriter#destroyRecord
78 * @param {Ext.data.Record} rec
81 destroyRecord : function(rec){
82 if(this.encodeDelete){
84 data[this.meta.idProperty] = rec.id;