0

尝试获取nodeEditControllerfromnodeController: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定义!

4

1 回答 1

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);
    },
    ...
于 2013-04-11T13:35:29.970 回答