1

私はMVCパターンに取り組んでいます。私は以下の2つの機能を持っています.1つは機能しており、もう1つは機能していません。私のコントローラーコードを見てください。

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 関数はうまく機能しています。しかし、そのコードを変更して確認メッセージ ボックスを追加すると、ストアを定義してもコードが機能しません。

この問題を解決する方法を教えてください。

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 に答える