PDA

View Full Version : Extjs tree error: Cannot call method 'getRootNode' of undefined



nsfl
25 Jan 2014, 8:44 PM
Hi,

I got error - Cannot call method 'getRootNode' of undefined - with my extjs mvc tree. The code is as follows:

TreeController.js


Ext.define(

'Am.example.controller.TreeController', {

extend:

'Ext.app.Controller',stores: ['TreeStore'],models: ['TreeModel'],views: ['user.Tree']
});

TreeModel.js

Ext.define('Am.example.model.TreeModel', {

extend:

'Ext.data.Model',fields: [{ name: 'name', type: 'string' }]
});

TreeStore.js

Ext.define('Am.example.store.TreeStore', {

extend:

'Ext.data.TreeStore',requires: [ 'Am.example.model.TreeModel' ],model: 'Am.example.model.TreeModel',autoLoad: true,proxy: {type: 'ajax',api: {read: 'Am/example/data/tree.json'

},reader: {type: 'json',root: 'children',successProperty: 'success'}}
});

Tree.js

Ext.define('Am.example.view.user.Tree' ,{

extend:

'Ext.tree.Panel',alias: 'widget.usertree',title: 'Notes',rootVisible: false,store: 'TreeStore'
});
tree.json

{"success": true,"childNodes": [{ "id": 1, "name": "Phil", "leaf": true },{ "id": 2, "name": "Nico", "expanded": true, "children": [{ "id": 3, "name": "Mitchell", "leaf": true }]},{ "id": 4, "name": "Sue", "loaded": true }]
}

Does anyone know what is wrong? Any help is appreciated.

Thanks & regards,

nsfl

Malte123
26 Jan 2014, 6:43 PM
what happens on Browser-Concole if you execute:




var test = Ext.widget('usertree', {

}).load().on('load', function(){

console.log('successfuly loaded ...');
})

Jarrod Roberson
26 Jan 2014, 7:05 PM
You need to set "rootVisible" = false in the TreeGridView configuration.



viewConfig: {
rootVisible: false
},

nsfl
27 Jan 2014, 9:59 PM
I got same error with code provided by Malte123
TypeError: Cannot call method 'getRootNode' of undefined

nsfl
27 Jan 2014, 10:03 PM
I use Ext.tree.Panel and have set rootVisible: false.

Jarrod Roberson
27 Jan 2014, 11:14 PM
every node must be called "children" you have the first one called "childNodes", they all have to be "children".


{"success": true,"childNodes": [{ "id": 1, "name": "Phil", "leaf": true },{ "id": 2, "name": "Nico", "expanded": true, "children": [{ "id": 3, "name": "Mitchell", "leaf": true }]},{ "id": 4, "name": "Sue", "loaded": true }]}

{"success": true,"children": [{ "id": 1, "name": "Phil", "leaf": true },{ "id": 2, "name": "Nico", "expanded": true, "children": [{ "id": 3, "name": "Mitchell", "leaf": true }]},{ "id": 4, "name": "Sue", "loaded": true }]}

nsfl
1 Feb 2014, 12:30 PM
every node must be called "children" you have the first one called "childNodes", they all have to be "children".


{"success": true,"childNodes": [{ "id": 1, "name": "Phil", "leaf": true },{ "id": 2, "name": "Nico", "expanded": true, "children": [{ "id": 3, "name": "Mitchell", "leaf": true }]},{ "id": 4, "name": "Sue", "loaded": true }]}

{"success": true,"children": [{ "id": 1, "name": "Phil", "leaf": true },{ "id": 2, "name": "Nico", "expanded": true, "children": [{ "id": 3, "name": "Mitchell", "leaf": true }]},{ "id": 4, "name": "Sue", "loaded": true }]}

Thanks. I have changed "childNodes" to "children", and I still got the same error.

Malte123
1 Feb 2014, 4:27 PM
ask me again next days (by PM) ... I am waiting for Sencha Inc. fix my Vote-Rating back to 60.... (so please give me a reminder)

(Someone votes all my Posts down... Support-Member "event" promised it will be fixed after weekend)

I am angry about this so I wi1l not help before this is done. But give me a reminder when you see my Vote on 60+
:)

PS: For me seeing vote goes up is motivation enough trying to be helpful...