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