控制器已定义,但无法找到

时间:2013-04-11 13:30:45

标签: ember.js

尝试从nodeEditController获取nodeController:startEditing时,我遇到以下问题:

Uncaught TypeError: Cannot call method 'set' of undefined

这是NodeController

SettingsApp.NodeController = Ember.ObjectController.extend({
    isEditing: false,

    startEditing: function () {
        debugger;
        var nodeEditController = this.get('controllers.nodeEdit');
        nodeEditController.set('content', this.get('content'));
        nodeEditController.startEditing();
        this.set('isEditing', true);
    },
    ...

这是NodeEditController

SettingsApp.NodeEditController = Ember.ObjectController.extend({
    needs: ['node'],

    startEditing: function () {
        //debugger;
        // add the contact and its associated phone numbers to a local transaction
        var node = this.get('content');
        var transaction = node.get('store').transaction();
        transaction.add(node);
        // contact.get('phones').forEach(function (phone) {
        //   transaction.add(phone);
        // });
        this.transaction = transaction;
    },
    ...

错误发生在行中:

nodeEditController.set('content', this.get('content'));

由于:

var nodeEditController = this.get('controllers.nodeEdit');

返回undefined。这是为什么? NodeEditController已定义!

1 个答案:

答案 0 :(得分:4)

NodeController缺少needs属性:

SettingsApp.NodeController = Ember.ObjectController.extend({
    needs : ["nodeEdit"],
    isEditing: false,

    startEditing: function () {
        debugger;
        var nodeEditController = this.get('controllers.nodeEdit');
        nodeEditController.set('content', this.get('content'));
        nodeEditController.startEditing();
        this.set('isEditing', true);
    },
    ...