3

展開時にツリーノードをソートしたい。次のコードを使用して、extjs 4.1.0itemexpandまたはbeforeItemExpandイベントでこれを行うのに苦労しています。ExtJS 4.2.1 では問題なく動作します。

ノードをクリックして展開すると、次のようになります。

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

コード:

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);
    }

});

4.1 では、使用されるイベントが itemExpand または beforeItemExpand の場合、上記のエラーが発生します。しかし、afterItemExpand を使用すると正常に動作します。4.2.1 では、他のイベントでも問題なく動作します...

なぜこれが起こっているのですか?代替手段はありますか?問題について不明な点がある場合はお知らせください ありがとう

4

1 に答える 1