-
1 Jul 2009 4:34 AM #1
Error with JSONStore
Error with JSONStore
Hi,
I have an issue with ExtJS 3.0 RC2 with JSONStore:
Here is my store:
and when I call load() with:Code:list_store[y] = new Ext.data.JsonStore({ storeId:nomS, url:function(){ if(y=='rien'){ var mon_url = 'requete3.php?id=' + pageVal+url_R[ongl_select]; } else{ var mon_url = 'requete3.php?id=' + pageVal+url_R[y]; } return mon_url; }, totalProperty: 'total', root: 'dataF', totalProperty: 'totalCount', success: function(){ alert('ok'); }, failure:function(){ alert('bug'); }, fields: eval(tab_cols), listeners:{ load:function(store){ var tmp = 'total'+y; if (window.XMLHttpRequest){ var page_connect = new XMLHttpRequest(); } else { if (window.ActiveXObject){ var page_connect=requete_ajax = new ActiveXObject("Microsoft.XMLHTTP"); } } page_connect.open ('GET', 'numero_page.php?ecran='+y, false); page_connect.send(null); var data_page = eval('('+page_connect.responseText+')'); var aff_page = data_page.page+'/'+data_page.nb; Ext.getCmp(tmp).setText('Total : '+store.getTotalCount()+' - Page '+aff_page); } } });
an exception is raised:Code:list_store[y].load();
I state that it works with ExtJS 2.2.Code:[Exception... "'Ext.data.Api: Invalid url. Please review your proxy configuration.' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
If someone knows... thanks in advance.
-
1 Jul 2009 4:48 AM #2
According to the docs, the URL must be a string.
It's only Ext.data.Connection that offers the ability to use a function.
Anyway, you are not using different URLs.
You are sending different parameters.
So what you need is a beforeload listener.Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
1 Jul 2009 4:52 AM #3
And what's this horror?
Code:if (window.XMLHttpRequest){ var page_connect = new XMLHttpRequest(); } else { if (window.ActiveXObject){ var page_connect=requete_ajax = new ActiveXObject("Microsoft.XMLHTTP"); } } page_connect.open ('GET', 'numero_page.php?ecran='+y, false); page_connect.send(null); var data_page = eval('('+page_connect.responseText+')'); var aff_page = data_page.page+'/'+data_page.nb; Ext.getCmp(tmp).setText('Total : '+store.getTotalCount()+' - Page '+aff_page);Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
1 Jul 2009 6:12 AM #4
Thanks for this fast answer!
I made it working by creating my url before, and just passing the string in the store.
But I still don't understand why it worked with ext 2.2 and not with 3.0... in the docs, nothing has changed apparently, so could you enlight me?
-
1 Jul 2009 6:34 AM #5
The way it creates URLs has changed.
You could try this override:
Code:Ext.override(Ext.data.DataProxy, { buildUrl : function(action, record) { record = record || null; var url = (this.api[action]) ? this.api[action].url : Ext.isFunction(this.url) ? this.url() : this.url; if (!url) { throw new Ext.data.Api.Error('invalid-url', action); } var format = null; var m = url.match(/(.*)(\.\w+)$/); // <-- look for urls with "provides" suffix, eg: /users.json, /users.xml, etc if (m) { format = m[2]; url = m[1]; } // prettyUrls is deprectated in favor of restful-config if ((this.prettyUrls === true || this.restful === true) && record instanceof Ext.data.Record && !record.phantom) { url += '/' + record.id; } if (format) { // <-- append the request format if exists (ie: /users/update/69[.json]) url += format; } return url; } });Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
1 Jul 2009 6:35 AM #6
If that works, try submitting it as a bug report.
Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
1 Jul 2009 7:29 AM #7
-
1 Jul 2009 7:30 AM #8
Ah well, you could debug it then.
Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
6 Jul 2009 1:18 AM #9
ok, the beforeload listener (thanks Animal) works for changing dynamically the url:
Code:beforeload: function(){ if(y=='rien'){ this.proxy.setUrl(url_R[ongl_select] + pageVal, false); } else{ this.proxy.setUrl(url_R[y] + pageVal, false); } },


Reply With Quote