ExtJS5: get rid of root property in proxy
I am trying to connect REST API to my ExtJS app.
For GET /user
identical requests, I return a response like this:
{items: [{id: 1, ...}, {id: 2, ....}], total: 2}
So, I created a model for this:
Ext.define('model.User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'name' },
],
proxy: {
reader: {
type: 'json',
totalProperty: 'total',
rootProperty: 'items'
},
type: 'rest',
url: '/Api/User',
}
});
Mesh loading data and everything looks perfect. Now I want to be able to request a single entry, which the api executes as {id: 1, ...}
. But when I do model.User.load(1)
, the success handler never gets triggered because the response does not contain a property items
. If I put my entry in this property it works, but it also looks ugly to other API users.
How can I get it to work without the root property? I cannot find any proxy / reader events on the model to dynamically change it.
source to share