【问题标题】:extjs Update when Changing Store Data更改商店数据时的 extjs 更新
【发布时间】:2012-01-15 11:55:46
【问题描述】:

我正在使用设计器,我的目标是更新到目前为止已通过单击 newBtn 启动的商店记录。我正在尝试在调用它的函数之外执行此操作。

如果我尝试点击按钮,它会起作用。

./application.js

Ext.Loader.setConfig({
    enabled: true
});

Ext.application({
    name: 'MyApp',

    stores: [
        'MyArrayStore'
    ],

    launch: function() {
        Ext.QuickTips.init();

        var cmp1 = Ext.create('MyApp.view.TradeGrid', {
            renderTo: Ext.getBody()
        });

     cmp1.show();


    //PROBLEM HERE  
    // This actually does something but when maxIndex is printed to the console it = 0
    // Meaning that no data has been loaded to grid
    // Am I wrong thinking it should? As the other file loads two data cells right away

       cmp1.addRecord([]);

    //PROBLEM HERE

./TradeGrid.js

Ext.define('MyApp.view.TradeGrid', {
    extend: 'MyApp.view.ui.TradeGrid',

    initComponent: function() {
        var me = this;


        me.callParent(arguments);

        var button = me.down('button[text=newBtn]');
        button.on('click', me.onSubmitBtnClick, me);

    },

    addRecord: function(myRecordArray) {

            var grid = Ext.getCmp("TradeGrid");  //defined by  -> Property: id 
            var store = grid.getStore();

            var maxIndex = store.getCount();
            console.log(maxIndex);               //maxIndex PRINT to CONSOLE


            var res = store.insert(maxIndex, [["ll", "kk", "00"]]);


            console.log(this);

    },

    onSubmitBtnClick: function() {
        this.addRecord([]);
    }




});

        }
    });

前两个数据加载到网格中

[
["Ace Supplies", "Emma Knauer", "555-3529"],
["Best Goods", "Joseph Kahn", "555-8797"],

]

【问题讨论】:

    标签: extjs grid


    【解决方案1】:

    我看到您使用 Ext.getCmp 获得了网格参考 - 这意味着您对组件的 id 进行了硬编码。这不是一个好主意,您最好尝试使用 itemId。它可能会导致一些奇怪的错误,也许这就是您无法正常工作的原因。尝试将 id 更改为 itemId。

    【讨论】:

    • 我最终破坏了设计器生成的代码,它真的没有为 websockets 做好准备,但是我现在拥有我的代码的方式你的答案有效。
    猜你喜欢
    • 2014-03-11
    • 2015-05-26
    • 1970-01-01
    • 2015-07-30
    • 1970-01-01
    • 2019-07-23
    • 1970-01-01
    • 2013-09-22
    • 2012-01-09
    相关资源
    最近更新 更多