Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.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 5:更改单个存储时,所有存储都会更新_Javascript_Extjs - Fatal编程技术网

Javascript ExtJS 5:更改单个存储时,所有存储都会更新

Javascript ExtJS 5:更改单个存储时,所有存储都会更新,javascript,extjs,Javascript,Extjs,我创建了一个选项卡面板,以图像为标题,以html为自定义组件。这些自定义组件使用存储,但我在更新单个变量(状态)时出错,所有变量都会更改。我在这里展示代码: 可选择按钮组件: Ext.require('Cat3.view.fsm.data.ButtonsStore'); /** * Selectable button with image */ Ext.define('Cat3.view.fsm.components.SelectableButtons', { extend: 'E

我创建了一个选项卡面板,以图像为标题,以html为自定义组件。这些自定义组件使用存储,但我在更新单个变量(状态)时出错,所有变量都会更改。我在这里展示代码:

可选择按钮组件:

Ext.require('Cat3.view.fsm.data.ButtonsStore');

/**
 * Selectable button with image
 */
Ext.define('Cat3.view.fsm.components.SelectableButtons', {
    extend: 'Ext.view.View',
    cls: 'selectable-buttons',
    alias: 'widget.selectable-buttons',
    tpl: [
        '<tpl for=".">',
            '<div class="thumb-wrap button button-{status}">',
                '<img src="resources/images/cards/{type}/{status}/{name}.png">',
                '<img src="resources/images/icons/icon_mandatory.png" class="button-tick button-tick-{status}">',
            '</div>',
        '</tpl>'
    ],

    // Set both to false if you want single select
    multiSelect: true,
    simpleSelect: true,

    trackOver: false,
    itemSelector: 'div.thumb-wrap',
    listeners: {
        select: function(ths, record, eOpts) {
            record.set('status', 'active');
            debugAmenaButtonStatus(this);
        },
        deselect: function(ths, record, eOpts) {
            record.set('status', 'passive');
        },
        selectionchange: function(selection) {
            this.refresh();
        },
        containerclick: function(ths, e, eOpts) {
            return false; // Stops the deselection of items
        }
    },
    initComponent: function() {
        var store = Ext.create('Cat3.view.fsm.data.ButtonsStore');
        this.setStore(store);
        this.callParent(arguments);
    }
});


debugAmenaButtonStatus = function(ref) {
    ref.up().up().items.items.forEach(function(tab) { // Tab
        console.log(tab.items.items[0].getStore().data.items[0].data.status); // Amena Button Status
    });
};

所有这些都可以正常工作,但当我选择SelectableButtons(一个选项卡)中的一个按钮时,每个选项卡中的同一个按钮都会更改其状态,并且只有活动选项卡中的一个选定按钮需要更改。你知道为什么吗?我已经检查了每个商店都是单独创建的,并且每个商店都有不同的id。

只是一个想法,为了更好地猜测,我需要看到它在以下方面发挥最佳作用:


如果“选择一个选择所有”,我的第一个想法是,所有按钮只是从所有地方引用的一个按钮。一个实例具有不同的名称。

请注意
Cat3.view.fsm.components.SelectableButtons上的行。
视图:

initComponent: function() {
    var store = Ext.create('Cat3.view.fsm.data.ButtonsStore');
    ...
}
你可能想把它改成

initComponent: function() {
    var store = new Ext.create('Cat3.view.fsm.data.ButtonsStore');
    ...
}

这将为您的视图创建一个新的
数据存储实例。

可能是由于在“Cat3.view.fsm.Data.buttonstore”中定义数据引起的问题,请在创建“Cat3.view.fsm.Data.buttonstore”后尝试使用loadData方法。例如(在Cat3.view.fsm.components.SelectableButtons内部),initComponent:function(){var store=Ext.create('Cat3.view.fsm.data.ButtonsStore');store.loadData()}哇,在不知道发生了什么的五个小时后,一切都正常了,谢谢!谢谢你的提示,我不知道Sencha有一个提琴页面,看起来非常有用!关于答案,最后第一条评论起了作用。
initComponent: function() {
    var store = Ext.create('Cat3.view.fsm.data.ButtonsStore');
    ...
}
initComponent: function() {
    var store = new Ext.create('Cat3.view.fsm.data.ButtonsStore');
    ...
}