2013-04-11 32 views
0

當試圖讓nodeEditControllernodeController: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; 
    }, 
    ... 

發生錯誤我N線:

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

因爲:

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

返回undefined。這是爲什麼? NodeEditController已定義!

回答

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); 
    }, 
    ... 
+0

的確!現在它可以工作。我儘快接受...... – dangonfast 2013-04-11 13:38:06

相關問題