Results 1 to 6 of 6

Thread: Problem loading data into a Json store

  1. #1
    Sencha Premium User
    Join Date
    Mar 2009
    Posts
    254

    Default Problem loading data into a Json store

    Following is the code for my Json store:

    Code:
    new Ext.data.JsonStore( {
    		// store configs
    		autoDestroy: true,
    		// reader configs
    		root: 'files',
    		idProperty: 'id',
    		fields: [ 'id', 'text', 'qtip' ]
    	})
    Please note that the Store should not load its data from some url, rather I need to manually load data into the store on some actions being performed somewhere else on the form.

    Here is what I do when those actions are performed:
    Code:
    var nodes = Ext.decode(response.responseText);
    var files = [];
    for (i = 0; i < nodes.length; i++) {
    	if (nodes[i].leaf) {
    		files.push(nodes[i]);
    	}
    }
    mystore.loadData(files, false);
    This always generates the following error:
    g is undefined
    http://localhost:8080/extjs/3.1.0/ext-all.js?u
    Line 7

    Any ideas of what I am doing wrong would be greatly appreciated.

  2. #2
    Sencha User fay's Avatar
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    1,750

    Default

    Are you sure that the data structure in "nodes" is correct?

    Use ext-all-debug.js, FireFox + FireBug, put a breakpoint at loadData and step into the code.
    Last edited by fay; 15 Feb 2010 at 6:55 AM. Reason: Typo

  3. #3
    Sencha Premium User
    Join Date
    Mar 2009
    Posts
    254

    Default

    Here's the output of console.log(Ext.encode(files)):

    Code:
    [{"id":"D:/xampp/htdocs/subdir/.buildpath","text":".buildpath","qtip":"Type: File<br />Last Modified: Feb 13, 2010, 3:14 pm<br />Size: 174 B","cls":"file","leaf":true},{"id":"D:/xampp/htdocs/subdir/.htaccess","text":".htaccess","qtip":"Type: File<br />Last Modified: Feb 14, 2010, 1:42 am<br />Size: 4 KB","cls":"file","leaf":true},
    The output is partial that should be sufficient for analysis.

  4. #4
    Sencha User fay's Avatar
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    1,750

    Default

    And did you...

    Use ext-all-debug.js, FireFox + FireBug, put a breakpoint at loadData and step into the code.
    Also, try initially setting data to empty:

    Code:
    new Ext.data.JsonStore( {
      // store configs
      autoDestroy: true,
      // reader configs
      root: 'files',
      idProperty: 'id',
      fields: [ 'id', 'text', 'qtip' ],
      data:[] // <--
    });

  5. #5
    Sencha Premium User
    Join Date
    Mar 2009
    Posts
    254

    Default

    Quote Originally Posted by fay View Post
    Also, try initially setting data to empty:

    });[/CODE]
    Well thanx, a variation of what you said worked. I had to set the data initially as:
    data:{files:[]}

    and later, in loadData as:
    store.loadData({files:files},false);

    And it works perfectly now. Thanx again.

  6. #6
    Sencha User
    Join Date
    Oct 2009
    Location
    Romania
    Posts
    56

    Default

    Your data should have the following format:
    Code:
    { files: [ ] }
    I see you are directly trying to load an array, but in fact you should load an object with the root property named "files", which should point to the array you are trying to load.
    I blog about JavaScript and Ext on http://jslog.com. Contact me for ExtJs support. Follow me @extjslog.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •