CodeWhisperer
CodeWhisperer

Reputation: 1195

Extjs How to load a JSON folder structure into a tree?

I'm trying to create a Extjs tree with JSON data. The data I want to load into the tree contains a folder structure. But when I trie to load the data into the tree, it doesn't show anything.

I have checked the json code here (JSONLint) on errors but everythin looks fine. Which would say that the problem probably is in the extjs part.

I have no idea how to get it works.

I have created a JSON-object like this:

{
"folders": [
    {
        "name": "Function",
        "id": "workspace://SpacesStore/000-000-000",
        "folders": [
            {
                "name": "Evaluation reports",
                "id": "workspace://SpacesStore/00-00-4949-9caf-6655fg"
            },
            {
                "name": "Function Reports",
                "id": "workspace://SpacesStore/554gg-563-sd555-872e-0098hhjf"
            },
            {
                "name": "Training(POP)",
                "id": "workspace://SpacesStore/4334g-67hj-4357-ba96-4343fhj343"
            }
        ]
    },
    {
        "name": "Application data",
        "id": "workspace://SpacesStore/3434gg-a761-48a2-83fa-3434f454hu",
        "folders": [
            {
                "name": "Application letters",
                "id": "workspace://SpacesStore/23232ff-c95f-4999-sdsd556-00886ggh7765"
            }
        ]
    }
]
}

This is the Extjs part where I want to load the JSON data:

initComponent: function() {

    // declare a new store and load tree data 
    this.store = new Ext.data.TreeStore({
        // set params
        proxy: {
            type: 'ajax',
            reader: 'json',
            url: 'http://localhost:8080/testApp/rest/folder/1'
        }
    });

    this.items = [{
        flex: 1
    }];
    this.callParent();
}

Upvotes: 1

Views: 354

Answers (1)

Evan Trimboli
Evan Trimboli

Reputation: 30092

You didn't tell the reader what property to read from:

reader: {
    type: 'json',
    rootProperty: 'folders'
}

Upvotes: 1

Related Questions