2012-05-21 47 views
1

煎茶觸摸2集標籤我是新來的MVC結構煎茶觸摸2.在控制器

在我看來,我有一個標籤,如下所示:

{ 的xtype:「標籤」, 的itemId: '標題', 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

也許需要看到你的控制器的代碼 – sirmdawg

+0

我添加了控制器代碼。謝謝! –

+0

基本上我希望答案標籤在問題標籤上點擊時顯示答案 –

回答

2

您需要將引用添加到您的標籤在你的控制器:

config: { 
    refs: { 
    yourlabel : #YOUR_LABEL_ID' 
    } 
    … 
} 

,然後在你的控制器,你可以通過調用this.getYourlabel();

所以訪問的標籤,以改變標題,你需要做的(無論你在你的控制器需要)

this.getYourlabel().setHtml('Label'); 

希望這幫助

2

給你的標籤有些id屬性值

,然後編寫下面的代碼在你的controller

..... 
..... // Controller code .. 
refs: { 
    answerLabel: '#answerLabel', 
    }, 
control: { 
    answerLabel: { 
     tap: 'answerLabelFn' 
    } 
} 
..... 
..... 
answerLabelFn : function() { 
     // Your Label tap handler code... 
}