1. #1
    Ext JS Premium Member
    Join Date
    May 2008
    Posts
    528
    Vote Rating
    0
    Eric24 is on a distinguished road

      0  

    Default Going insane with JsonStore

    Going insane with JsonStore


    I am using a JsonStore with a Grid:

    Code:
    Layout.ds = new Ext.data.JsonStore({
        url : 'sheldon.json',
        params : {},
        root : 'items',
        fields : ['author', 'manufacturer', 'productgroup', 'title']
    });
    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:
    {
            "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"
                }
            ]
    }
    What am I missing (going on two days now of reading and trying everything I can get my hands on to no avail)?

    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

  2. #2
    Ext User
    Join Date
    Nov 2007
    Posts
    56
    Vote Rating
    0
    Gordon76 is on a distinguished road

      0  

    Default


    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.

    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
    I am not sure if the Json Reader can read from file:///
    Have your tried this:

    Code:
    var ds = new Ext.data.JsonStore({
        url : 'file:///sheldon.json',
        params : {},
        root : 'items',
        fields : ['author', 'manufacturer', 'productgroup', 'title']
    });
    ds.load()
    Returns an "Access to file from Script denied" error for me.

    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

  3. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    ScriptTagProxy won't help. Think about the name.

  4. #4
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    5
    mjlecomte will become famous soon enough mjlecomte will become famous soon enough

      0  

    Default


    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?

  5. #5
    Ext JS Premium Member
    Join Date
    May 2008
    Posts
    528
    Vote Rating
    0
    Eric24 is on a distinguished road

      0  

    Default


    [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?

  6. #6
    Ext User
    Join Date
    Jul 2007
    Posts
    3,128
    Vote Rating
    1
    devnull is an unknown quantity at this point

      0  

    Default


    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.