1

私はSenchaTouch2を使い始めたばかりで、SenchaTouch1.xを使ったことがありません。このチュートリアルを終了しました(これは、これまでに見つけた中で最高のスターターチュートリアルです)http://miamicoder.com/2012/how-to-create-a-sencha-touch-2-app-part-1/そして今、私は先に進んでこのNotesアプリを拡張したいと思います。

コントローラーと2つのビュー、リストビューと編集ビューがあります。編集ビューで、現在のレコードを削除できるようにしたい。削除機能はコントローラーにあります。削除ボタンをタップした後、確認ダイアログ(「削除してもよろしいですか...?」)を表示したいのですが。ユーザーが「はい」を押した後、削除関数を呼び出す必要があります。

今私の問題は次のとおりです:Ext.Msg.confirm内からコントローラーの削除関数を呼び出すにはどうすればよいですか?

これが私のコードの関連するスニペットです。重要なものが足りない場合はお知らせください。

「onDeleteNoteCommand」関数を参照してください。「this」はDOMWindowであるため、「this.someFunction」は明らかに機能しません。

Ext.define('TestApp2.controller.Main', {
extend: 'Ext.app.Controller',

config: {
    refs: {
        noteEditorView: 'noteeditorview'
    },
    control: {
        noteEditorView: {
            deleteNoteCommand: 'onDeleteNoteCommand',
        }
    }
},

onDeleteNoteCommand: function() {
    console.log('onDeleteNoteCommand');

    var noteEditor = this.getNoteEditorView();
    var currentNote = noteEditor.getRecord();

    Ext.Msg.confirm(
        "Delete note?",
        "Do you reall want to delete the note <i>"+currentNote.data.title+"</i>?",
        function(buttonId) {
            if(buttonId === 'yes') {
                            //controller functions!! how to call them?
                this.deleteNote(currentNote);                   
                this.activateNotesList();
            }
        }
    );
},

deleteNote: function(record) {
    var notesStore = Ext.getStore('Notes');
    notesStore.remove(record);
    notesStore.sync();
},

activateNotesList: function() {
    Ext.Viewport.animateActiveItem(this.getNotesListView(), this.slideRightTransition);
},

slideLeftTransition: { type: 'slide', direction: 'left' },
slideRightTransition: { type: 'slide', direction: 'right' },

launch: function() {
    this.callParent();
    Ext.getStore('Notes').load();
    console.log('launch main controller');
},
init: function() {
    this.callParent();
    console.log('init main controller');
}
});
4

1 に答える 1

4

Ext.Msgのコールバック関数に入ると、スコープがコントローラースコープからグローバルスコープ(ウィンドウ)に変わるため、confirmメソッドのパラメーターとして設定する必要があります。

  Ext.Msg.confirm(
      "Delete note?",
      "Do you reall want to delete the note <i>"+currentNote.data.title+"</i>?",
      function(buttonId) {
        if(buttonId === 'yes') {
          this.deleteNote(currentNote);                   
          this.activateNotesList();
        }
      }, 
      this // scope of the controller 
    );

詳細については、senchaドキュメントを確認してください:http://docs.sencha.com/touch/2-0/# !/ api / Ext.MessageBox-method-confirm

于 2012-05-24T11:11:14.760 に答える