Reputation: 1087
Client(Browser) is automatically appending "id" in my JSON which I am sending to server. Here is my model with proxy:
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'
}
}
When I create a model object to send data to server via Rest, Rest fill the 'id' field with (NameOfMymodel-number).
This is code to create and send model object to server via Rest:
var UserStore = Ext.getStore('peopleStore');
var user = Ext.create('ThemeApp.model.peopleModel',{'title': "Test", 'body': "Testing" });
user.save(); //POST /users
UserStore.load();
Is there any way to stop extjs from appending such id with my data?
This is a similar kind of problem but not what I am looking. how do i prevent an extjs model/proxy from saving the empty primary id on create
Upvotes: 5
Views: 3515
Reputation: 1
You can use the Ext.data.proxy.Rest property: appendId
appendId : Boolean True to automatically append the ID of a Model instance when performing a request based on that single instance. See Rest proxy intro docs for more details. Defaults to: true
inside your proxy like this
proxy: {
type: 'rest',
api: {
read: 'services/test',
},
appendId: false, // Prevents appending the ID to the URL
reader: {
type: 'json',
rootProperty: 'data',
messageProperty: 'processMessage'
}
}
Upvotes: 0
Reputation: 1087
Just set persist to false and that's it
Ext.define('ThemeApp.model.peopleModel', {
extend: 'Ext.data.Model',
fields: [ {name: 'id', type: 'int', persist: false},
{name: 'xyz', type: 'auto'}]
}
The 'idProperty' default value is 'id', so simply set persist: false for id property in your model. credits: ajokon (Pointed this in comments by referring to another stackoverflow question)
Upvotes: 8