我是Sencha Touch 2的MVC结构的新手。
在我看来,我的标签如下:
{ xtype:'label', itemId:'title', html:'标题' }
在我的控制器中,如何设置此标签的值?
目前我的控制器(处理教程样本):
Ext.define(“NotesApp.controller.Notes”,{
extend: "Ext.app.Controller", config: { refs: { // We're going to lookup our views by xtype. noteView: "noteview", noteEditorView: "noteeditorview", notesList: "#notesList" }, control: { noteView: { // The commands fired by the notes list container. noteNextCommand: "onNoteNextCommand", noteAnswerCommand: "onNoteAnswerCommand" }, noteEditorView: { // The commands fired by the note editor. saveNoteCommand: "onSaveNoteCommand", deleteNoteCommand: "onDeleteNoteCommand", backToHomeCommand: "onBackToHomeCommand" } } }, onNoteNextCommand: function () { var noteView = this.getNoteView(); console.log("loaded view"); //set label here }, // Base Class functions. launch: function () { this.callParent(arguments); var notesStore = Ext.getStore("Notes"); notesStore.load(); console.log("launch"); }, init: function () { this.callParent(arguments); console.log("init"); } });
完整的查看代码:
Ext.define(“NotesApp.view.Note”,{ extend:“Ext.Container”, 别名:“widget.noteview”,
config: { layout: { type: 'fit' }, items: [ { xtype: "toolbar", title: "Random Question", docked: "top", items: [ { xtype: 'spacer' }, { xtype: "button", text: 'List', ui: 'action', itemId: "list" } ] }, { xtype: "label", html: 'question', itemId: "question" }, { xtype: "label", html: 'answer', itemId: "answer" } ], listeners: [{ delegate: "#list", event: "tap", fn: "onListTap" }, { delegate: "#question", event: "tap", fn: "onQuestionTap" }, { delegate: "#answer", event: "tap", fn: "onAnswerTap" }] }, onListTap: function () { console.log("list"); this.fireEvent("showList", this); }, onQuestionTap: function () { console.log("noteAnswer"); this.fireEvent('noteAnswer', this); }, onAnswerTap: function () { console.log("noteNext"); this.fireEvent('noteNext', this); } });
答案 0 :(得分:2)
为您的标签添加一些id
属性值
{
xtype: "label",
html: 'answer',
id: "answerLabel"
}
然后在controller
。
.....
..... // Controller code ..
refs: {
answerLabel: '#answerLabel',
},
control: {
answerLabel: {
tap: 'answerLabelFn'
}
}
.....
.....
answerLabelFn : function() {
// Your Label tap handler code...
}
答案 1 :(得分:2)
您需要在控制器中添加对标签的引用:
config: {
refs: {
yourlabel : #YOUR_LABEL_ID'
}
…
}
然后在您的控制器中,您可以通过调用this.getYourlabel();
因此,为了更改标题,您需要(在控制器中的任何位置)
this.getYourlabel().setHtml('Label');
希望这有帮助