Results 1 to 4 of 4

Thread: Error on populating Ext Js Tree with JSON store

  1. #1
    Ext JS Premium Member
    Join Date
    Dec 2011
    Posts
    29
    Answers
    1
    Vote Rating
    0
      0  

    Default Error on populating Ext Js Tree with JSON store

    I'm trying to create ExtJs Tree using this code.

    Code:
    Ext.define('User', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'name', mapping: 'name'}
        ]
    });
    
    var store = Ext.create('Ext.data.TreeStore', {
        model: 'User',   
        proxy: {
            type: 'ajax', // rest
            url : 'tree.json',
            reader: {
                type: 'json',
                root: 'pdb.user.filterResults.partnerFilter.column'
            }
        },
        autoLoad: true,
        autoSync: true,
        root: {
            name: "Root node",
            id: '0',
            expanded: true
        }
    });
    My JSON structure is-
    Code:
    {"pdb":{"user":{"filterResults":{"partnerFilter":{"column":[{"id":"HomeGeography","name":"Home GEO"},{"id":"BusinessModel","name":"Business Model"}]}}}}}
    I'm getting problem in populating tree.

    Please suggest
    Last edited by skirtle; 7 Dec 2011 at 10:17 PM. Reason: Added CODE tags

  2. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585
    Vote Rating
    394
      0  

    Default

    I'm getting problem in populating tree.
    Could you be more specific?

    A few suggestions.

    Get rid of autoLoad and autoSync.

    Your model is missing your id field. Is that intentional?

    A treepanel defaults to having a single column with a dataIndex of text. Have you configured your name field as a column in your tree?

    Code:
    columns: [{
        dataIndex: 'name',
        xtype: 'treecolumn'
    }]

  3. #3
    Ext JS Premium Member
    Join Date
    Dec 2011
    Posts
    29
    Answers
    1
    Vote Rating
    0
      0  

    Default

    Hi Skirtle,
    I worked on your suggestion, but the problem still there. error is in this part of code.

    Code:
     var store = Ext.create("Ext.data.TreeStore", {
        model: "Pdb",   
        proxy: {
            type: "ajax", // rest
            url : "tree.json",
            reader: {
                type: "json",
                root: "pdb.user.filterResults.partnerFilter.column"
                    }
        },
     root: {
        name: "Root node",
        id: "0",
        expanded: true
    }, 
    sorters: [{
        property: "id",
        direction: "ASC" // DESC
    }]
    });
    Error is "obj.pdb is undefined". is it because of nested root in store. we used to work in the same manner in data.store. Is this feature not supported in data.TreeStore? If I remove nested root and modify my json as well, then its working fine. Please suggest.

  4. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585
    Vote Rating
    394
      0  

    Default

    If you can remove the need for a root then do. Trees are currently a bit confused and use the root to signify the node containing the children. I imagine the problem is trying to read nested children, even though you don't have any.

    If you can't simplify your JSON then I think you may have to resort to overriding getResponseData on the reader.

Tags for this Thread

Posting Permissions

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