michael.jets
14 Apr 2011, 1:14 AM
Model:
Ext.regModel('Company', {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type : 'string'}],
proxy: {
type: 'rest',
appendId: true,
url : 'http://'+API_SERVER_HOST+'/companies',
format: 'json'
}
});
I have trouble to get resource from server use REST. It is always send request to /companies.json. when I do next:
Ext.ModelMgr.getModel('Company').load(1, {success:function(r){console.log(r.getId())}})
Solution to fix code for RestProxy in method buildUrl:
buildUrl: function()
var records = request.operation.records || [],
record = records[0],
format = this.format,
url = request.url || this.url;
var record_id = (record) ? record.getId() : request.operation.id;
if (this.appendId && record_id) {
if (!url.match(/\/$/)) {
url += '/';
}
url += record_id;
}
if (format) {
if (!url.match(/\.$/)) {
url += '.';
}
url += format;
}
request.url = url;
return Ext.data.RestProxy.superclass.buildUrl.apply(this, arguments);
Ext.regModel('Company', {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type : 'string'}],
proxy: {
type: 'rest',
appendId: true,
url : 'http://'+API_SERVER_HOST+'/companies',
format: 'json'
}
});
I have trouble to get resource from server use REST. It is always send request to /companies.json. when I do next:
Ext.ModelMgr.getModel('Company').load(1, {success:function(r){console.log(r.getId())}})
Solution to fix code for RestProxy in method buildUrl:
buildUrl: function()
var records = request.operation.records || [],
record = records[0],
format = this.format,
url = request.url || this.url;
var record_id = (record) ? record.getId() : request.operation.id;
if (this.appendId && record_id) {
if (!url.match(/\/$/)) {
url += '/';
}
url += record_id;
}
if (format) {
if (!url.match(/\.$/)) {
url += '.';
}
url += format;
}
request.url = url;
return Ext.data.RestProxy.superclass.buildUrl.apply(this, arguments);