2013-06-04 23 views
1

在我的簡單的應用程序,我聽爲disclose事件是這樣的:正確方法(或任何其他)在煎茶事件處理觸摸

NotesList.js(視圖)文件...

Ext.define("NotesApp.view.NotesList", { 
    extend : "Ext.dataview.List", 
    xtype : "noteslist", 
    ... 
    config : { 
     onItemDisclosure : true,  //adds the disclose arrow 
    } 
}); 

NotesList用於NotesListContainer這是一個Ext.Container

然後在NotesListContainer.js(圖)...

var notesList = { 
     xtype : "noteslist", 
     ... 
     listeneres : { 
      disclose : { fn : this.onNotesListDisclose, scope : this } 
     } 
    }; 

    this.add([topToolbar, notesList]); 

功能做到這一點:

onNotesListDisclose : function(list, record, target, index, evt, options) { 
    console.log(' onNotesListDisclose() called'); //nevers gets logged 
    this.fireEvent('editNoteCommand', this, record); 
} 

然後在Notes.js(控制器):

refs : { 
     //get elemets using xtype attr 
     notesListContainer : "noteslistcontainer", 
     noteEditor : "noteeditor" 
    }, 
    //handlers for events 
    control : { 
    //define which events should this controller respond to 

    notesListContainer : { 
     //events fired by NotesListContainer 
     newNoteCommand : "onNewNoteCommand", 
     editNoteCommand : "onEditNoteCommand" 
    } 
    } 
}, 
//Event/Command handler 

onEditNoteCommand : function(list, record) { 
    console.log(' onEditNoteCommand called '); 
    this.activateNoteEditor(record); 
} 

我覺得問題在NotesListContainer.js中,我正在實例化列表。 如果我聽聽這樣的控制器事件:

refs : { 
     //get elemets using xtype attr 
     notesListContainer : "noteslistcontainer", 
     notesList : "noteslistcontainer list", 
    }, 
    //handlers for events 
    control : { 
    //define which events should this controller respond to 
    notesListContainer : { 
     //events fired by NotesListContainer 
     newNoteCommand : "onNewNoteCommand", 
     //editNoteCommand : "onEditNoteCommand" 
    }, 
    notesList : { 
     disclose : "onEditNoteCommand" //adding it this way works... 
    } 
    } 

它工作得很好。但是,我寧願使用更多的應用程序特定事件,而不是非常通用的disclose事件。 我是新來的sencha touch,任何幫助表示讚賞。

回答

1

如果你想擁有自己的自定義業務邏輯驅動的事件,請執行下列操作:

  • 訂閱在必要的UI事件您的主控制器
  • 生成應用程序廣泛的業務事件
  • 在您的視圖控制器中訂閱這些事件
+0

謝謝,你能否發現上述代碼不能按預期工作的原因,即'onEditNoteCommand'方法永遠不會被調用。 –

+1

您仍然需要訂閱通用的「披露」事件。沒有其他辦法了。然而,在處理程序內部,你可以做一些簡單的事情,比如'this.getParent()。fireEvent('editItem')' - 這樣你可以在容器級別上生成你自己的editItem事件。 – sha

+0

這就是我正在做的。你可以在代碼中看到第二個和第三個代碼片段。但是控件永遠不會到達'onNotesListDisclose'(在第三個代碼片段中) –