저는 Sencha Touch 2를 처음 사용하기 시작했습니다. 이전에는 Sencha Touch 1.x를 사용한 적이 없습니다. 방금이 튜토리얼을 끝 냈습니다. (지금까지 찾은 최고의 튜토리얼입니다) http://miamicoder.com/2012/how-to-create-a-sencha-touch-2-app-part-1/ 이제이 Notes App을 확장하고 싶습니다.Sencha Touch 2 : Ext.Msg.confirm 내에서 컨트롤러 기능 호출
저는 컨트롤러와 2 개의보기, 목록보기 및 편집보기를 가지고 있습니다. 편집보기에서 현재 레코드를 삭제할 수 있기를 원합니다. 삭제 기능이 컨트롤러에 있습니다. 삭제 버튼을 누른 후 확인 대화 상자를 표시하려고합니다 ("정말 하시겠습니까?"). 사용자가 yes를 누르면, delete 함수가 호출되어야합니다.
내 문제는 다음과 같습니다. Ext.Msg.confirm에서 컨트롤러 삭제 기능을 호출하려면 어떻게해야합니까?
다음은 내 코드의 관련 스 니펫입니다. 중요한 것이 빠졌는지 알려주세요.
"onDeleteNoteCommand"기능을 참조하십시오. "this.someFunction"은 "this"가 DOMWindow이므로 분명히 작동하지 않습니다. 자세한 내용은
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
);
: 당신이 Ext.Msg의 콜백 함수를 입력하면
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');
}
});
안녕하십니까, 답변 해 주셔서 감사합니다.하지만 나는 오해했다고 생각합니다. onDeleteNoteCommand 이벤트가 정상적으로 호출됩니다. "onDeleteNoteCommand"내에 확인 상자가 나타납니다. 다른 컨트롤러 기능을 호출하고 싶습니다. 희망이 분명하다. – Simon
"this"를 확인 메소드의 네 번째 매개 변수로 추가하면됩니다. –
오, 고마워요! :-) 너무 단순하지만 아직 여기있는 문서에서도 알아낼 수 없습니다 : http://dev.sencha.com/deploy/ext-1.1.1/docs/output/Ext.MessageBox.html 이제 Ext.MessageBox의 Public 메서드를 살펴 보았습니다. 범위가 있습니다! – Simon