修改后的代码对于getvalue和setvalue

时间:2015-07-23 23:32:40

标签: javascript html extjs javascript-events extjs4

  1. 我的代码工作正常,但他们想要更改我的代码....
    1. 他们希望将setValue和getValue直接添加到 footballPanel而不是体育网,
    2. 但在添加后,代码工作正常......
    3. 你能告诉我为什么它不起作用......
    4. 在下方提供我修改过的代码......
    5. 我正在执行的ui动作是有两个单选按钮, 当我点击每个单选按钮时,打开两个不同的网格
    6. 在其中一个网格中我们添加值,当我切换回另一个收音机 按钮,另一个网格中的值消失但不应该消失 消失...
    7. 在我修改代码后,值消失了,你能告诉我原因吗
  2. 此处仅修改代码的一部分

    else {
            this.setDisabled(true);
            this.addCls("sports-item-disabled");
            if (sportsGrid.store.getCount() > 0) {
               var footballPanel = sportsGrid.up('panel');
               footballPanel.holdValue = footballPanel.getValue();
               footballPanel.setValue();
               sportsGrid.addCls("sports-item-disabled");
            }
       }
    

    整个修改后的代码:

    sportsContainerHandler: function(radioGroup, newValue, oldValue, options) {
            var sportsCustomParams = options.sportsCustomParams;
            var uiPage = this.up('football-ux-sports-ui-page');
            var SportsDefinition = metamodelsHelper.getSportsDefinition(
                uiPage, sportsCustomParams.SportsHandlerDefinitionId);
            var sportsFieldParam = SportsDefinition.params['sportsMultiFieldName'];
            var sportsGrid = uiPage.queryById(sportsFieldParam.defaultValue).grid;
            if (newValue[radioGroup.name] == 'sportss') {
                this.setDisabled(false);
                this.removeCls("sports-item-disabled");
                if (sportsGrid.holdValue) {
                    var footballPanel = sportsGrid.up('panel');
                    footballPanel.setValue(sportsGrid.holdValue);
                }
            } else {
                this.setDisabled(true);
                this.addCls("sports-item-disabled");
                **if (sportsGrid.store.getCount() > 0) {
                    var footballPanel = sportsGrid.up('panel');
                    footballPanel.holdValue = footballPanel.getValue();
                    footballPanel.setValue();
                    sportsGrid.addCls("sports-item-disabled");
                }**
            }
        },
    

    无需修改的工作代码

    sportsContainerHandler: function(radioGroup, newValue, oldValue, options) {
        var sportsCustomParams = options.sportsCustomParams;
        var uiPage = this.up('football-ux-sports-ui-page');
        var SportsDefinition = metamodelsHelper.getSportsDefinition(
            uiPage, sportsCustomParams.SportsHandlerDefinitionId);
        var sportsFieldParam = SportsDefinition.params['sportsMultiFieldName'];
        var sportsGrid = uiPage.queryById(sportsFieldParam.defaultValue).grid;
        if (newValue[radioGroup.name] == 'sportss') {
            this.setDisabled(false);
            this.removeCls("sports-item-disabled");
            if (sportsGrid.holdValue) {
                var footballPanel = sportsGrid.up('panel');
                footballPanel.setValue(sportsGrid.holdValue);
            }
        } else {
            this.setDisabled(true);
            this.addCls("sports-item-disabled");
            if (sportsGrid.store.getCount() > 0) {
                sportsGrid.holdValue = sportsGrid.store.data.items;
                sportsGrid.store.loadData([]);
                sportsGrid.addCls("sports-item-disabled");
            }
        }
    },
    

1 个答案:

答案 0 :(得分:0)

getValue()不是ExtJS Panel class的方法。

您的代码从sportsGridExt.grid.Panel)到footbalPanelExt.panel.Panel)的更改不起作用,因为它们来自不同的类,因此具有不同的属性和方法。

如果您希望此代码有效,则需要实施getValue()setValue()。例如,像:

在FootballPanel上:

getValue: function () {
    return this.down('grid').store.data.items;
},

setValue: function (newValue) {
    if (!newValue)
        newValue = new Array();

    this.down('grid').store.loadData(newValue);
},

并使用修改过的代码:

sportsContainerHandler: function(radioGroup, newValue, oldValue, options) {
    var sportsCustomParams = options.sportsCustomParams;
    var uiPage = this.up('football-ux-sports-ui-page');
    var SportsDefinition = metamodelsHelper.getSportsDefinition(
        uiPage, sportsCustomParams.SportsHandlerDefinitionId);
    var sportsFieldParam = SportsDefinition.params['sportsMultiFieldName'];
    var sportsGrid = uiPage.queryById(sportsFieldParam.defaultValue).grid;
    if (newValue[radioGroup.name] == 'sportss') {
        this.setDisabled(false);
        this.removeCls("sports-item-disabled");
        if (sportsGrid.holdValue) {
            var footballPanel = sportsGrid.up('panel');
            footballPanel.setValue(sportsGrid.holdValue);
        }
    } else {
        this.setDisabled(true);
        this.addCls("sports-item-disabled");
        if (sportsGrid.store.getCount() > 0) {
            var footballPanel = sportsGrid.up('panel');
            footballPanel.holdValue = footballPanel.getValue();
            footballPanel.setValue([]);
            sportsGrid.addCls("sports-item-disabled");
        }
    }
},