Ext.JS防止代理发送额外的字段 [英] Ext.JS Prevent Proxy from sending extra fields
问题描述
这是我的模型:
Ext.define('A.model.Group', {
extend: 'Ext.data.Model',
fields:['id', 'name'],
proxy: {
type: 'rest',
url: '/group',
reader: {
type: 'json',
root: 'data'
},
writer: {
type: 'json',
writeAllFields: false
}
}
});
模型正在树中通过TreeStore使用
The model is being used in a Tree via a TreeStore
问题是当一个 PUT
, POST
或 DELETE
方法是完成的,而不是仅从JSON有效载荷中的模型中发送字段,还会发送来自 Ext.data.NodeInterface
的字段。以下是一个示例负载:
The problem is that when a PUT
, POST
or DELETE
method is done, instead of sending only fields from the model in the JSON payload, fields from Ext.data.NodeInterface
are also sent. Here is an example payload:
{"id":"","name":"TestGroup","parentId":"8","index":0,"depth":3,"checked":null}
< >我不想要额外的字段 parentId
, index
, depth
和选中
发送。什么是最好的方法呢?我不想在服务器上忽略它们。
I don't want the extra fields parentId
, index
, depth
, and checked
to be sent. What is the best way to do this? I don't want to have to ignore them on the server.
推荐答案
如果您不想只发送具体数据服务器,writeAllFields不是解决方案,就好像设置为false,它只发送修改的字段。
您的问题的解决方案是定义您自己的作者并覆盖方法 getRecordData
这里是一个可行的示例:
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
}
});
这篇关于Ext.JS防止代理发送额外的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!