客户端(浏览器)自动在我的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
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'
}
}
Run Code Online (Sandbox Code Playgroud)
当我创建一个模型对象以通过Rest向服务器发送数据时,Rest使用(NameOfMymodel-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();
Run Code Online (Sandbox Code Playgroud)
有没有办法阻止extjs用我的数据附加这样的id?
这是一个类似的问题,但不是我正在寻找的. 我如何阻止extjs模型/代理在创建时保存空的主要ID
只是设置为false,就是这样
Ext.define('ThemeApp.model.peopleModel', {
extend: 'Ext.data.Model',
fields: [ {name: 'id', type: 'int', persist: false},
{name: 'xyz', type: 'auto'}]
}
Run Code Online (Sandbox Code Playgroud)
'idProperty'默认值为'id',因此只需为模型中的id属性设置persist:false即可.学分:ajokon(通过引用另一个stackoverflow问题在评论中指出这一点)