PDA

View Full Version : GRID CRUD (REST) -> Only able to get "GET" and "POST"



BastianKrones
22 Apr 2013, 12:06 AM
Hi all,
i have worked on a grid in Sencha Architect 2.2 (Ext.JS).

43272

I used RowEditingPluing to edit each line:
43273

But i use 2 different JSON-Files:
1) Main-JSON-File ("Users"):

Ext.define('MyApp.store.Users', { extend: 'Ext.data.Store',


requires: [
'MyApp.model.User'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
autoSync: true,
model: 'MyApp.model.User',
storeId: 'Users',
proxy: {
type: 'ajax',
url: 'http://localhost/sencha/api/user',
reader: {
type: 'json',
idProperty: 'id',
root: 'data'
}
}
}, cfg)]);
}
});

Second JSON-File ("contact"):

Ext.define('MyApp.store.Contacts', { extend: 'Ext.data.Store',


requires: [
'MyApp.model.Contact'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
autoSync: true,
model: 'MyApp.model.Contact',
storeId: 'MyJsonStore1',
proxy: {
type: 'ajax',
url: 'http://localhost/sencha/api/contact',
reader: {
type: 'json',
root: 'data'
}
}
}, cfg)]);
}
});

My Model "User":

Ext.define('MyApp.model.User', { extend: 'Ext.data.Model',


clientIdProperty: 'id',


fields: [
{
name: 'name'
},
{
name: 'emailAddress'
},
{
name: 'age'
},
{
name: 'birthdate',
type: 'date'
},
{
name: 'gender'
},
{
name: 'getNewsletter',
type: 'boolean'
},
{
name: 'contactFK'
},
{
name: 'id'
}
]
});

My Model "Contact":

Ext.define('MyApp.model.Contact', { extend: 'Ext.data.Model',


fields: [
{
name: 'ContactID'
},
{
name: 'Name'
},
{
name: 'SourceContacTID'
},
{
name: 'CustomerFK'
},
{
name: 'DateCreated'
},
{
name: 'BasePriority'
}
]
});

Contact is used to fill a dropdown ( combobox ) in the grid.

If i "update" some row, i get following request:

Request URL:
http://localhost/sencha/api/user?_dc=1366617771342
Request Method:
POST
Status Code:
201 Created
age: 30
birthdate: "1930-01-01T00:00:00"
contactFK: 8296
emailAddress: "[email protected]"
gender: "M"
getNewsletter: true
id: 68
name: "Billy Tinnes"[/CODE]

in JSON there is an ID, but it should be sent like sencha/api/user/{id}

How do i solve it?

I didn't try delete yet, but i guess it will be the same?
Anyone has an idea how to solve it?

Thanks alot.

existdissolve
22 Apr 2013, 5:55 PM
Have you tried using a Rest proxy?

http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.data.proxy.Rest

BastianKrones
22 Apr 2013, 11:07 PM
Hi existdissolve,
thanks a lot, i didn't see the obvious thing.

In my store i changed my Ajax-proxy to REST-proxy (copied and pasted the url "http://localhost/sencha/api/user") and it worked.

Thanks so much.
So, this "problem" is solved