尝试从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
已定义!
答案 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);
},
...