Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ExtJS:Widget组合在我单击expand时重置所有字段的值_Javascript_Extjs_Extjs6.2 - Fatal编程技术网

Javascript ExtJS:Widget组合在我单击expand时重置所有字段的值

Javascript ExtJS:Widget组合在我单击expand时重置所有字段的值,javascript,extjs,extjs6.2,Javascript,Extjs,Extjs6.2,我正在使用一个treePanel,其中一列在单元格内使用带有组合框的widgetColumn 下面是示例代码 { text: 'TC', dataIndex: 'scrTC', xtype: 'widgetcolumn', widget: { xtype: 'combo', store: 'TCStore', valueField: 'value', displayField: 'displayVal

我正在使用一个
treePanel
,其中一列在单元格内使用带有组合框的
widgetColumn

下面是示例代码

{
    text: 'TC',
    dataIndex: 'scrTC',
    xtype: 'widgetcolumn',
    widget: {
        xtype: 'combo',
        store: 'TCStore',
        valueField: 'value',
        displayField: 'displayValue',
        matchFieldWidth: false,
    }
}
当我为几行更改combo的值,然后展开网格中的其他子项时,所有combo值都会再次重置为默认值。不确定这里的问题是什么

商店代码:

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

    proxy: {
        type: 'ajax',
        url: 'resources/data/tree/TC.json'
    }
});
treepanel的屏幕截图:

当我单击另一个子节点时,例如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());
                            }
                        }
                    }
                }
            }]
        }
    });

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

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

您可以在这里查看工作

代码片段

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

                            }
                        }
                    }
                }]
            }
        })
    }
});

我找到了解决办法

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

这就解决了我的问题。

你能在a中显示吗?我尝试了小提琴,但当我运行时,我看不到任何输出,我的代码也做了更改&我收到了错误,因为“treeview.getRecord不是函数”可能是你的代码中遗漏了什么。你能发布你的代码吗?只需在代码中签入此
treeview=combo.up('treeview')
不可用。上面的行返回未定义,因此我使用了combo.up('myTree')--这是对我的树面板的引用。您需要使用此
combo.up('treeview')
更改此
combo.up('treeview')
。因为
treecview
是特定的行。当然,在我的情况下不起作用的东西会起作用,它是未定义的。