问题
I want to the sort the tree node when it is expanded. I have been struggling to do this in extjs 4.1.0 with itemexpand
or beforeItemExpand
event using the following code. It works fine in ExtJS 4.2.1.
When I click on node to expand, I get this:
Uncaught TypeError: Cannot read property 'internalId' of undefined at:
ns[i].viewRecordId = records[i].internalId
in updateIndexes : function(startIndex, endIndex) method of Ext.view.AbstractView
class
Code:
var mystore = Ext.create('Ext.data.TreeStore', {
fields: ['displayName', 'type', 'value', 'stateSize', 'percentOfParent'],
root: {
"displayName": "state",
"name": "state",
"stateSize": 1.91,
"percentOfParent": 100.0,
"percentOfTotalstate": 100.0,
"leaf": false,
"cls": "highlight-new",
"children": [{
"displayName": "Component Tree",
"name": "Tree",
"stateSize": 0.25,
"percentOfParent": 13.0,
"percentOfstate": 13.0,
"leaf": true,
"cls": "highlight-new",
"iconCls": "task",
}, {
"displayName": "crap",
"name": "Tree",
"stateSize": 0.25,
"percentOfParent": 13.0,
"percentOfstate": 13.0,
"leaf": true,
"cls": "highlight-new",
"iconCls": "task",
}]
});
Ext.define('xyz.mytree', {
extend: 'Ext.tree.Panel',
title: 'State',
alias: 'widget.state',
width: 150,
height: 150,
columns: [{
xtype: 'treecolumn',
header: 'Name',
dataIndex: 'displayName',
width: 300
}, {
header: 'Type',
dataIndex: 'type',
width: 275
}, {
header: 'Value',
dataIndex: 'value',
align: 'left',
width: 275
}, {
header: 'Size (KB)',
dataIndex: 'stateSize',
align: 'right',
width: 95
}, {
header: '% Of Parent',
dataIndex: 'percentOfParent',
align: 'right',
width: 95
}],
store: mystore,
listeners: {
itemExpand: function (node) {
sortFunction = function (o1, o2) {
if (o1.data.displayName < o2.data.displayName) {
return -1;
} else if (o1.data.displayName > o2.data.displayName) {
return 1;
} else {
return 0;
}
};
if (!node.expanded) {
node.sort(sortFunction, false, false);
node.expanded = true;
}
}
},
constructor: function (config) {
this.callParent(arguments);
}
});
In 4.1, if the event used is itemExpand or beforeItemExpand, I receive the above error. But if I use afterItemExpand it works fine. in 4.2.1 it works fine on other events as well...
Any ideas why this is happening? Is there any alternative? Let me know if something is not clear abt the problem Thanks
回答1:
I got the same issue while using Ext.view.View
So as suggested here I changed
itemSelector: 'div'
to
itemSelector: 'div#someId'
https://architectslog.wordpress.com/2013/05/13/sencha-ext-js-4-and-cannot-read-property-internalid-of-undefined/
来源:https://stackoverflow.com/questions/17558355/uncaught-typeerror-cannot-read-property-internalid-of-undefined-while-sortin