Ext.JS Prevent Proxy from sending extra fields Ext.JS Prevent Proxy from sending extra fields json json

Ext.JS Prevent Proxy from sending extra fields


If you wan't to send only specific data to server, writeAllFields is not the solution as if is set to false it only sends the modified fields. The solution for your problem is defining your own writer and overriding the method getRecordData here is a posible example:

var newWriter = Ext.create('Ext.data.writer.Json',{  getRecordData: function(record){       return {'id':record.data.id,'name':record.data.name};  }})Ext.define('A.model.Group', {    extend: 'Ext.data.Model',    fields:['id', 'name'],    proxy: {        type: 'rest',        url: '/group',        reader: {            type: 'json',            root: 'data'        },        writer: newWriter    }});


the NodeInterface adds these fields into your model:

{name: 'parentId',   type: idType,    defaultValue: null},{name: 'index',      type: 'int',     defaultValue: null, persist: false},{name: 'depth',      type: 'int',     defaultValue: 0, persist: false},{name: 'expanded',   type: 'bool',    defaultValue: false, persist: false},{name: 'expandable', type: 'bool',    defaultValue: true, persist: false},{name: 'checked',    type: 'auto',    defaultValue: null, persist: false},{name: 'leaf',       type: 'bool',    defaultValue: false},{name: 'cls',        type: 'string',  defaultValue: null, persist: false},{name: 'iconCls',    type: 'string',  defaultValue: null, persist: false},{name: 'icon',       type: 'string',  defaultValue: null, persist: false},{name: 'root',       type: 'boolean', defaultValue: false, persist: false},{name: 'isLast',     type: 'boolean', defaultValue: false, persist: false},{name: 'isFirst',    type: 'boolean', defaultValue: false, persist: false},{name: 'allowDrop',  type: 'boolean', defaultValue: true, persist: false},{name: 'allowDrag',  type: 'boolean', defaultValue: true, persist: false},{name: 'loaded',     type: 'boolean', defaultValue: false, persist: false},{name: 'loading',    type: 'boolean', defaultValue: false, persist: false},{name: 'href',       type: 'string',  defaultValue: null, persist: false},{name: 'hrefTarget', type: 'string',  defaultValue: null, persist: false},{name: 'qtip',       type: 'string',  defaultValue: null, persist: false},{name: 'qtitle',     type: 'string',  defaultValue: null, persist: false},{name: 'children',   type: 'auto',   defaultValue: null, persist: false}

two of them dont have `persist' property.

Most of NodeInterface's fields default to persist: false. This means they are non-persistent fields by default. Non-persistent fields will not be saved via the Proxy when calling the TreeStore's sync method or calling save() on the Model. In most cases, the majority of these fields can be left at their default persistence setting, but there are cases where it is necessary to override the persistence of some fields. The following example demonstrates how to override the persistence of a NodeInterface field. When overriding a NodeInterface field it is important to only change the persist property. name, type, and defaultValue should never be changed.
Override the fields like this:

 { name: 'iconCls', type: 'string',  defaultValue: null, persist: true },


You can add a serializer to the fields in the model you do not want to send to the server.

var makeUndefined = function(value, record) {    return undefined;}var fieldsOfYourModel = [    {        serialize: makeUndefined,        name: 'parentId'    },    {        serialize: makeUndefined,        name: 'index'    }];

serialize is a function which converts the Model's value for this Field into a form which can be used by whatever Writer is being used to sync data with the server. http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Field-cfg-serialize

serialize is available since Ext JS 4.1.1.