PDA

View Full Version : Ext.data.proxy.Server.buildUrl(): You are using a ServerProxy but have not supplied i



ZyBeR
28 Mar 2014, 2:56 PM
I'm trying to load a simple json struck into a store, but are having problems.....

Apparently I can't use normal url's with query strings?
I wan't to use this: /callbacks/scoring_archive/search.php?act=read&uuid=f1d69fbe-8f54-11df-82cf-0050569d2b85&limit=20&page=1

Now I have this store, which is not working. It's not even trying to load anything, just throwing the error message in the title.

I understand I can't use uuid as I have in the proxy, but I did it to show what I would like todo.



Ext.define('LiveScoring.store.Search', {
extend: 'Ext.data.Store',


config: {
storeId: 'Search',
model: 'LiveScoring.model.Search',
autoLoad: true,

proxy: {
type: 'ajax',
url: '/callbacks/scoring_archive/search.php',
acation: 'read',
uuid: 'f1d69fbe-8f54-11df-82cf-0050569d2b85',
page: 1,
start: 1,
limit: 20,
reader: {
type: 'json',
root: '',
idProperty: 'game_id'
}
},


listeners: {
load: function(store, records){
console.log('Loaded!');
}
}
}
});

Fredric Berling
29 Mar 2014, 1:22 AM
Do not put the proxy inside the config object.



Ext.define('LiveScoring.store.Search', {
extend: 'Ext.data.Store',

storeId: 'Search',
model: 'LiveScoring.model.Search',
autoLoad: true,

proxy: {
type: 'ajax',
url: '/callbacks/scoring_archive/search.php',
acation: 'read',
uuid: 'f1d69fbe-8f54-11df-82cf-0050569d2b85',
page: 1,
start: 1,
limit: 20,
reader: {
type: 'json',
root: '',
idProperty: 'game_id'
}
},

listeners: {
load: function(store, records){
console.log('Loaded!');
}
}

});

Fredric Berling
29 Mar 2014, 1:50 AM
Or even better. Specify the proxy on the model instead.

ZyBeR
29 Mar 2014, 2:32 AM
Or even better. Specify the proxy on the model instead.
Thank you, I'll try that. In Sencha Touch I always have the proxy in the store, but maybe it's different in ExtJS?

Anyhow, what's the correct way of building url's?

Page, limit etc. are automatically added, how do I go ahead and add custom parameters?

skirtle
29 Mar 2014, 5:09 PM
If the parameters are fixed then you can add them directly to the url config or use the extraParams config.

For anything more sophisticated I'd write a custom proxy. Details here:

http://skirtlesden.com/articles/custom-proxies

ZyBeR
31 Mar 2014, 3:17 AM
Thanks guys, your recommendations worked!Now, I'm just trying to figure out how to use the Operations object to configure stuff like limit etc.?http://docs.sencha.com/extjs/4.0.7/#!/api/Ext.data.OperationHow do I incorporate that in this code?




Ext.define('LiveScoring.model.Search', {
extend: 'Ext.data.Model',


fields: [
{ name: 'id', type: 'int' },
{ name: 'uuid', type: 'string' },
{ name: 'company', type: 'string' },
{ name: 'lanes', type: 'int' },
{ name: 'game_id', type: 'int' },
{ name: 'name', type: 'string' },
{ name: 'team_id', type: 'int' },
{ name: 'group_id', type: 'int' },
{ name: 'team', type: 'string' },
{ name: 'game', type: 'int' },
{ name: 'score', type: 'int' },
{ name: 'timestamp', type: 'int' },
{ name: 'visitors_current', type: 'int' },
{ name: 'in_pa', type: 'boolean' }
],

proxy: {
type: 'ajax',
url: '/callbacks/scoring_archive/search.php',
extraParams: {
act: 'read',
uuid: 'f1d69fbe-8f54-11df-82cf-0050569d2b85',
limit: 50
},
reader: {
type: 'json',
root: 'games'
}
}
});

skirtle
31 Mar 2014, 3:36 PM
I'm not sure I understand the question.

Usually you'd just call loadPage on the store. That will create an Operation which will be passed to the proxy. Operation is little more than a light-weight wrapper around some standard query options (like paging, sorting, etc.). The proxy is then responsible for mapping those options to a suitable request. The article I mentioned previously explains how to customize that last stage of the process.

I actually disagree with the advice about moving the proxy onto the model. You should put it where it's appropriate. If you want to use it to load a single model then put it on the model, whereas if you want to load multiple models into a store then you should put it on the store. The proxy on the model is inherited by the store, so in some cases it can be useful to configure the proxy on the model as a default for all of its stores, but I've found that to be rarely useful in practice as different stores usually need slightly different proxies.