2012-07-09 34 views
4

我仍然試圖通過this tutorial工作,但取得了不同的成功。在我的控制器劇本,我有以下幾點:使用ref getter函數返回undefined

config: { 
     refs: { 
      notesListContainer: 'noteslistcontainer', 
      noteEditor: 'noteeditor' 
     }, 
     control: { 
      notesListContainer: { 
       newNoteCommand: 'onNewNoteCommand', 
       editNoteCommand: 'onEditNoteCommand' 
      } 
     } 
}, 
onEditNoteCommand: function(list, record) { 
    console.log('onEditNoteCommand'); 

    this.activateNoteEditor(record); 
}, 
activateNoteEditor: function(record) { 
     var noteEditor = this.getNoteEditor(); 
     noteEditor.setRecord(record); 
     Ext.Viewport.animateActiveItem(noteEditor, this.slideLeftTransition); 
}, 

當我在Chromium 18.0.1025.168運行此,我得到

Uncaught TypeError: Cannot call method 'setRecord' of undefined Notes.js:37`. 
`this.getNoteEditor()' 

不返回noteEditor,但返回undefined。

整個項目的來源可用here

回答

7

重要的是使用autoCreate : true

config: { 
    refs: { 
     notesListContainer: 'noteslistcontainer', 
     noteEditor: { 
       selector: 'noteeditor', 
       xtype: 'noteeditor', 
       autoCreate: true // missing 
      } 
     }, 
    }, 
... 
} 
+0

加入該行的代碼裁判後,指定裁判爲自動創建的,我仍然得到同樣的錯誤。 – 2012-07-09 17:02:26

+0

太急於在語法上犯錯誤。主要想法是將表單定義爲autoCreated – olegtaranenko 2012-07-09 17:04:59

+0

是的!解決了這個問題。謝謝! – 2012-07-09 17:12:14