-
16 May 2008 2:27 PM #1
Going insane with JsonStore
Going insane with JsonStore
I am using a JsonStore with a Grid:
The header of the grid renders fine on page load. A button on the form calls Layout.ds.load() and Firebug confirms that the json file is loaded. I then get a loadexception event from the JsonStore, but the only argument is "object Object" (which isn't of any use). The json file being loaded is:Code:Layout.ds = new Ext.data.JsonStore({ url : 'sheldon.json', params : {}, root : 'items', fields : ['author', 'manufacturer', 'productgroup', 'title'] });
What am I missing (going on two days now of reading and trying everything I can get my hands on to no avail)?Code:{ "items":[ { "author":"Sidney Sheldon", "manufacturer":"Warner Books", "productgroup":"Book", "title":"Master of the Game" }, { "author":"Sidney Sheldon", "manufacturer":"Warner Books", "productgroup":"Book", "title":"Are You Afraid of the Dark?" }, { "author":"Sidney Sheldon", "manufacturer":"Warner Books", "productgroup":"Book", "title":"If Tomorrow Comes" }, { "author":"Sidney Sheldon", "manufacturer":"Warner Vision", "productgroup":"Book", "title":"Tell Me Your Dreams" }, { "author":"Sidney Sheldon", "manufacturer":"Warner Books", "productgroup":"Book", "title":"Bloodline" }, { "author":"Sidney Sheldon", "manufacturer":"Warner Books", "productgroup":"Book", "title":"The Other Side of Me" }, { "author":"Sidney Sheldon", "manufacturer":"Warner Books", "productgroup":"Book", "title":"A Stranger in the Mirror" }, { "author":"Sidney Sheldon", "manufacturer":"William Morrow & Company", "productgroup":"Book", "title":"The Sky Is Falling" }, { "author":"Sidney Sheldon", "manufacturer":"Warner Books", "productgroup":"Book", "title":"Nothing Lasts Forever" }, { "author":"Sidney Sheldon", "manufacturer":"Warner Books", "productgroup":"Book", "title":"The Naked Face" } ] }
Is there any useful information available to shed some light on why the loadexception is firing?
Also, API docs say that "loadexception" fires for either the proxy or the store, with different arguments. How to tell them apart?
PS: I was originally using a store with an XML reader, but my XML source file is on my local file system, not being served by an HTTP server. I found the note about the XML reader requiring a text/xml HTTP header, so figured this was the problem. That's why I moved to using a JsonStore instead. Is there any such limitation (Json reader can't read from file://)?
Thanks!
Eric
-
17 May 2008 3:58 AM #2
Hmm, I've tried loading your Json via the loadData method and this works fine. Maybe you can set up an event Listener for the beforeload, load or loadexception and call Firebug's debugger method to see what's going on. "object Object" sounds to me like a toString() method is invoked where it shouldn't be invoked.
I am not sure if the Json Reader can read from file:///Code:var ds = new Ext.data.JsonStore({ url : 'sheldon.json', params : {}, root : 'items', fields : ['author', 'manufacturer', 'productgroup', 'title'] }); ds.loadData({ "items":[ { "author":"Sidney Sheldon", "manufacturer":"Warner Books", "productgroup":"Book", "title":"Master of the Game" }, { "author":"Sidney Sheldon", "manufacturer":"Warner Books", "productgroup":"Book", "title":"Are You Afraid of the Dark?" } ] }); ds.getAt(0) // -> will return the first item
Have your tried this:
Returns an "Access to file from Script denied" error for me.Code:var ds = new Ext.data.JsonStore({ url : 'file:///sheldon.json', params : {}, root : 'items', fields : ['author', 'manufacturer', 'productgroup', 'title'] }); ds.load()
I'm no expert on this, but maybe the Ext.data.ScriptTagProxy might help you get around this. Basically, what you are trying to do is include a local ressouce dynamically, right? I think that's what the ScriptTagProxy does. It uses the Script element to get data from somewhere, usually a remote host to circumvent the Same Origin Policy, but maybe this works with local files as well. Someone correct me when I'm wrong on this. (see Animal's post below)
There is also a bunch of threads about running ext without a webserver on the forum, which all lead to this extension:
http://extjs.com/forum/showthread.php?t=21681
-
17 May 2008 6:51 AM #3
ScriptTagProxy won't help. Think about the name.
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
-
17 May 2008 6:58 AM #4
There's a grid faq in my signature you may want to consult, there's a post in it with listeners.
I'd post your code along with the response seen from firebug. Is your mapping commensurate to the data packet received?MJ
API Search || Ext 3: docs-demo-upgrade guide || User Extension Repository
Frequently Asked Questions: FAQs
Tutorial: Grid (php/mysql/json) , Application Design and Structure || Extensions: MetaGrid, MessageWindow
-
17 May 2008 10:33 AM #5
[Solved] The issue was solved with Ext-BaseX (JsonReader could not read from a local file).
But I'm still puzzled by how to get useful information from a load or loadexception event. My event handler function is firing, but all I ever get as arguments is "object Object", which does not seem to match any of the signatures in the API docs. There must be something I'm not understanding here, but what?
-
19 May 2008 8:31 AM #6
you mentioned firebug, so i assume you are using it. if you log an object to the console, or stop code execution at a certain point, you can click on objects in the console and examine their contents.
It sounds like you may want to look for some firebug tutorials on the net.


Reply With Quote