3

我想在树节点展开时对其进行排序。我一直在努力使用以下代码在 extjs 4.1.0 中使用itemexpand或事件来做到这一点。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

0

我在使用时遇到了同样的问题Ext.view.View

所以按照这里的建议 我改变了

itemSelector: 'div'

itemSelector: 'div#someId'

https://architectslog.wordpress.com/2013/05/13/sencha-ext-js-4-and-cannot-read-property-internalid-of-undefined/

于 2017-09-20T10:20:42.953 回答