Home | Mail | Syndicate

welcome to my space

12 March, 2010 |

JsonReader won't read data

  • Hey, ive been trying to make a app which uses the JsonReader function, but the data doesnt parse into to the grind?

    my ext.data.Store function:

    ds = new Ext.data.Store({
    proxy: new Ext.data.ScriptTagProxy({url:'LINK TO DB'}),
    reader: new Ext.data.JsonReader(
    {root: "data", id: "uniqid"},
    [
    {
    name: 'uniqid',
    type:'int'
    },
    {
    name: 'checked', type:'boolean'
    },
    {
    name: 'caller'
    },
    {
    name: 'player'
    },
    {
    name: 'reason'
    },
    {
    name: 'date'
    },
    {
    name: 'server'
    }
    ]
    )
    }
    );


    my Json data file:
    {data:[{uniqid:64536344,checked:false,caller:"SGulseth",player:"A player",reason:"A reason",date:"1197386965",server:"ip:port"}]}


    Firebug doesn't show any warnings or error.

    Someone who sees the error?

    Thanks


  • And read the docs on ScriptTagProxy!

    Thouroughly.


  • If you are not returning the data object wrapped in a callback as per the ScriptTagProxy instructions, no data will be loaded.


  • I assume you have your URL on a separate domain than the ext app, thus the ScriptTagProxy...

    Also, if you are not really using the id field for some reason, it is optional in your JsonReader, and you can leave out the root property as well and just return the data itself. I have had the best results doing something like:

    var reader = new Ext.data.JsonReader({ },
    [
    {name: "id" },
    {name: "field1"},
    {name: "fied2"}
    ]
    );
    // data looks like [{"id":1,"field1":"val 1", "field2":"val2"}]


  • Yes, i'm calling load. The uniqid was just a mistake when I copied the file.
    Hmm, tried that earlier, didnt get any more knowledge. btw. I followed Scott Walter's screencast guide, "Building A Grid using extjs"


  • http://extjs.com/deploy/dev/docs/?class=Ext.data.ScriptTagProxy

    Quote from the top of the docs...

    The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript source code that is used as the source inside a