2012-05-21 5 views
1

Я новичок в структуре MVC с Сенча сенсорный 2.Сенча Touch 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", { продлить: "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... 
}