1

我正在研究 MVC 模式。我有两个功能,一个是工作,另一个是不工作。看看我的控制器代码;

Ext.define('MyApp.controller.program', {
    extend: 'Ext.app.Controller',

    stores: [
        'program'
    ],

    deleteWithConfirm: function(button, e, options) {
    var viewList = Ext.ComponentQuery.query('#programGrid')[0];
        var selection = viewList.getSelectionModel().getSelection()[0];
        if(selection)
        {
        Ext.MessageBox.confirm('Confirm', 'Are you sure you want to do that?', 
        function(btn, text ) {
            if(btn == 'yes') {
            console.log('yes clicked');

            this.getProgramStore().remove(selection); //console error message: "TypeError: this.getProgramStore is not a function"
            this.getProgramStore().sync();

            }
            if(btn == 'no') {
            console.log('no clicked');
            }
        }
        );
    }
    },

    justDelete: function(button, e, options) {
        var viewList = Ext.ComponentQuery.query('#programGrid')[0];
        var selection = viewList.getSelectionModel().getSelection()[0];
        if(selection)
        {
            this.getProgramStore().remove(selection);
            this.getProgramStore().sync();
        }
},


init: function(application) {
    this.control({
        "#tombolHapusProgram": {
            click: this.deleteWithConfirm //this is not working

    //click: this.justDelete //this is working
        }
    });
}

});

justDelete 功能运行良好。但是当我修改该代码并添加一个消息框确认时,即使我定义了 store,该代码也不起作用。

你能告诉我如何解决这个问题吗?

4

2 回答 2

2

您需要设置回调的范围:

Ext.Msg.confirm('A', 'B', function() {
}, this);
于 2013-03-16T00:07:49.907 回答
0

无论如何,您的商店实例都绑定到网格,因此只需执行以下操作:

viviewList.getStore().remove(selection)
于 2013-03-16T05:48:44.427 回答