3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.data.JsonWriter"></div>/**
15 * @class Ext.data.JsonWriter
16 * @extends Ext.data.DataWriter
17 * DataWriter extension for writing an array or single {@link Ext.data.Record} object(s) in preparation for executing a remote CRUD action.
19 Ext.data.JsonWriter = function(config) {
20 Ext.data.JsonWriter.superclass.constructor.call(this, config);
22 // careful to respect "returnJson", renamed to "encode"
23 // TODO: remove after v3 final release
24 if (this.returnJson != undefined) {
25 this.encode = this.returnJson;
28 Ext.extend(Ext.data.JsonWriter, Ext.data.DataWriter, {
29 <div id="cfg-Ext.data.JsonWriter-returnJson"></div>/**
30 * @cfg {Boolean} returnJson <b>Deprecated</b>. Use {@link Ext.data.JsonWriter#encode} instead.
32 returnJson : undefined,
33 <div id="cfg-Ext.data.JsonWriter-encode"></div>/**
34 * @cfg {Boolean} encode <tt>true</tt> to {@link Ext.util.JSON#encode encode} the
35 * {@link Ext.data.DataWriter#toHash hashed data}. Defaults to <tt>true</tt>. When using
36 * {@link Ext.data.DirectProxy}, set this to <tt>false</tt> since Ext.Direct.JsonProvider will perform
37 * its own json-encoding. In addition, if you're using {@link Ext.data.HttpProxy}, setting to <tt>false</tt>
38 * will cause HttpProxy to transmit data using the <b>jsonData</b> configuration-params of {@link Ext.Ajax#request}
39 * instead of <b>params</b>. When using a {@link Ext.data.Store#restful} Store, some serverside frameworks are
40 * tuned to expect data through the jsonData mechanism. In those cases, one will want to set <b>encode: <tt>false</tt></b>, as in
41 * let the lower-level connection object (eg: Ext.Ajax) do the encoding.
45 <div id="method-Ext.data.JsonWriter-render"></div>/**
46 * Final action of a write event. Apply the written data-object to params.
47 * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
48 * @param {Record[]} rs
49 * @param {Object} http params
50 * @param {Object} data object populated according to DataReader meta-data "root" and "idProperty"
52 render : function(action, rs, params, data) {
53 if (this.encode === true) {
54 params[this.meta.root] = Ext.encode(data);
57 params.jsonData[this.meta.root] = data;
60 <div id="method-Ext.data.JsonWriter-createRecord"></div>/**
61 * Implements abstract Ext.data.DataWriter#createRecord
63 * @param {Ext.data.Record} rec
66 createRecord : function(rec) {
67 return this.toHash(rec);
69 <div id="method-Ext.data.JsonWriter-updateRecord"></div>/**
70 * Implements abstract Ext.data.DataWriter#updateRecord
72 * @param {Ext.data.Record} rec
75 updateRecord : function(rec) {
76 return this.toHash(rec);
79 <div id="method-Ext.data.JsonWriter-destroyRecord"></div>/**
80 * Implements abstract Ext.data.DataWriter#destroyRecord
82 * @param {Ext.data.Record} rec
85 destroyRecord : function(rec) {