使用ref getter函数返回undefined

时间:2012-07-09 15:46:12

标签: sencha-touch sencha-touch-2

我仍在尝试通过this tutorial,但取得了不同程度的成功。在我的控制器脚本中,我有以下内容:

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

1 个答案:

答案 0 :(得分:7)

重要的是使用autoCreate : true

将ref指定为autoCreated
config: {
    refs: {
        notesListContainer: 'noteslistcontainer',
        noteEditor: {
                 selector: 'noteeditor',
                 xtype: 'noteeditor',
                 autoCreate: true // missing
            }
        },
    },
...
}