Extjs-停止客户端以附加任何;id";在通过REST将模型实例发送到服务器之前
客户端(浏览器)在我发送给服务器的JSON中自动添加“id”。 这是我的代理模型:Extjs-停止客户端以附加任何;id";在通过REST将模型实例发送到服务器之前,extjs,sencha-cmd,Extjs,Sencha Cmd,客户端(浏览器)在我发送给服务器的JSON中自动添加“id”。 这是我的代理模型: fields: ['id','title','body'], idProperty: 'id', // this is the default value (for clarity) // clientIdProperty: 'cliendID', identifier: 'sequential', // to generate -1, -2 etc on the client
fields: ['id','title','body'],
idProperty: 'id', // this is the default value (for clarity)
// clientIdProperty: 'cliendID',
identifier: 'sequential', // to generate -1, -2 etc on the client
proxy: {
type: 'rest',
//appendId: false,
limitParam:"",
filterParam: "",
startParam:'',
pageParam:'',
url:'http://localhost:3000/posts',
headers: {'Content-Type': "application/json" },
reader: {
type: 'json',
rootProperty:'posts'
},
writer: {
type: 'json'
}
}
当我创建一个模型对象以通过Rest将数据发送到服务器时,Rest用(nameofmodel number)填充“id”字段
这是通过Rest创建模型对象并将其发送到服务器的代码:
var UserStore = Ext.getStore('peopleStore');
var user = Ext.create('ThemeApp.model.peopleModel',{'title': "Test", 'body': "Testing" });
user.save(); //POST /users
UserStore.load();
有没有办法阻止extjs在我的数据中附加这样的id
这是一个类似的问题,但不是我所看到的。
只需将persist设置为false,就是这样
Ext.define('ThemeApp.model.peopleModel', {
extend: 'Ext.data.Model',
fields: [ {name: 'id', type: 'int', persist: false},
{name: 'xyz', type: 'auto'}]
}
“idProperty”默认值为“id”,因此只需在模型中为id属性设置persist:false即可。
信用:ajokon(在评论中提到了另一个stackoverflow问题)[有没有办法在Extjs中禁用模型的“idProperty”?][1][1]:@ajokon非常感谢,这正是我想要的。