PDA

View Full Version : Issue while migrating from EXTJS 4.0.7 to EXTJS 4.1



kavyakn
29 Jul 2012, 7:44 PM
While migrating from EXTJS 4.0.7 to EXTJS 4.1 I get the following error
Uncaught TypeError: Cannot call method 'get' of undefined

for the following snippet of code:

var requireData = Ext.getCmp('treePanelId').getSelectionModel().getSelection();
var nodeId = requireData[0].get('id');

requireData[0] is undefined here.
Here 'treePanelId' is the id of the tree panel and 'id' is the attribute of the tree nodes.

It works perfectly in EXTJS 4.0.7 but not in EXTJS 4.1

Can you provide some solution ?

scottmartin
29 Jul 2012, 9:19 PM
What if you examine each step



tree = Ext.getCmp('treePanelId');
selModel = tree.getSelectionModel(),
selectedNode = selModel.getSelection()[0];


Does each resolve as expected?

Scott.

kavyakn
30 Jul 2012, 8:17 PM
No the last one i.e selectedNode is undefined.

scottmartin
30 Jul 2012, 9:03 PM
This works as expected in 4.1.1. Load app, select node, click button:



var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [
{ text: "detention", leaf: true },
{ text: "homework", expanded: true, children: [
{ text: "book report", leaf: true },
{ text: "alegrbra", leaf: true}
] },
{ text: "buy lottery tickets", leaf: true }
]
}
});

var tree = Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
store: store,
rootVisible: false,
renderTo: Ext.getBody()
});

Ext.create('Ext.Button', {
text: 'Click me',
renderTo: Ext.getBody(),
handler: function() {
var selModel = tree.getSelectionModel();
console.log(selModel);
selectedNode = selModel.getSelection()[0];
console.log(selectedNode);
}
});
‚Äč

Scott.