2

我正在使用treePanel其中一列widgetColumn与单元格内的组合一起使用。

下面是示例代码。

{
    text: 'TC',
    dataIndex: 'scrTC',
    xtype: 'widgetcolumn',
    widget: {
        xtype: 'combo',
        store: 'TCStore',
        valueField: 'value',
        displayField: 'displayValue',
        matchFieldWidth: false,
    }
}

当我更改几行的组合值然后在网格中展开其他子项时,所有组合值都会再次重置为默认值。不确定这里有什么问题。

商店代码:

Ext.define('TC', {
    extend: 'Ext.data.Store',
    storeId: 'TCStore',
    model: 'CommonModel',
    autoLoad: true,

    proxy: {
        type: 'ajax',
        url: 'resources/data/tree/TC.json'
    }
});

树形面板截图:

树形面板截图

当我单击另一个子节点时,例如 3 或 4,它会重置所有行中所有组合的值。

感谢帮助。

在下面的答案之后代码发生了变化,这给出了 getRecord 未定义的错误。

Ext.define('MyTree', {
    extend: 'Ext.tree.Panel',
    reference: 'myTree',
    columns: {

            item:[{
                text: 'TC',
                dataIndex: 'scrTC',
                xtype: 'widgetcolumn',
                widget: {
                    xtype: 'combo',
                    store: 'TCStore',
                    valueField: 'value',
                    displayField: 'displayValue',
                    matchFieldWidth: false,
                    listeners: {
                        change: function (combo) {
                            if (combo.hasFocus) {
                                var treeview = combo.up('myTree'), //myTree is reference of my treepanel
                                    record = treeview.getRecord(combo.el.up('tr')); ///getting error here
                                record.set('scrTC', combo.getValue());
                            }
                        }
                    }
                }
            }]
        }
    });
4

2 回答 2

0

您正在使用该属性dataIndex: 'scrTC',而您只是更改组合的值而不是 this scrTC。当您的节点展开或折叠时,它会再次设置相同的scrTC值。

因此scrTC,当您更改组合的值时,您需要更改 的值。

你可以在这里查看工作FIDDLE

代码片段

Ext.application({
    name: 'Fiddle',

    launch: function () {

        Ext.create('Ext.data.Store', {
            storeId: 'TCStore',
            autoLoad: true,
            proxy: {
                type: 'ajax',
                url: 'TC.json'
            }
        });

        Ext.create('Ext.data.TreeStore', {

            storeId: 'treeStore',

            fields: ['name'],
            root: {
                name: 'Root',
                expanded: true,
                scrTC: 1,
                children: [{
                    name: 'One',
                    scrTC: 2,
                    children: [{
                        name: 'Child 1',
                        scrTC: 3,
                        leaf: true
                    }, {
                        name: 'Child 2',
                        scrTC: 4,
                        leaf: true
                    }]
                }, {
                    name: 'Two',
                    scrTC: 5,
                    leaf: true
                }]
            },

        });

        Ext.create('Ext.tree.Panel', {

            store: 'treeStore',

            renderTo: Ext.getBody(),

            title: 'Tree Panel Demo',
            columns: {
                defaults: {
                    width: 200
                },
                items: [{
                    xtype: 'treecolumn',
                    dataIndex: 'name'
                }, {
                    xtype: 'widgetcolumn',
                    dataIndex: 'scrTC',
                    widget: {
                        xtype: 'combo',
                        store: 'TCStore',
                        valueField: 'value',
                        displayField: 'displayValue',
                        matchFieldWidth: false,
                        listeners: {
                            change: function (combo) {
                                if (combo.hasFocus) {
                                    var record = combo.getWidgetRecord(),
                                        property = combo.getWidgetColumn().dataIndex;

                                    record.set(property, combo.getValue());
                                }

                            }
                        }
                    }
                }]
            }
        })
    }
});
于 2018-09-03T05:38:34.050 回答
0

我找到了解决方案,

select: function (combobox, record) {
        combobox.getWidgetRecord().set(combobox.getWidgetColumn().dataIndex, record.data.value);
    }

这解决了我的问题。

于 2018-09-04T12:07:29.603 回答