2

I'm trying to create a new record in ember. In the past I used to manually create each of the model's fields on the object controller, but that really seems superfluous. With the code in this fiddle, as I start typing information into the text boxes, I get an error

Assertion failed: Cannot delegate set('name', t) to the 'content' property of object proxy <App.StockNewController:ember258>: its 'content' is undefined
4

2 回答 2

3

基本上你缺少的是在你的App.StockNewController. 因为当您的模板中定义的绑定启动并且在您的支持控制器上没有定义此类属性时,您会收到错误消息。我已经改变了一点,现在错误消失了。

App.StockNewController = Em.ObjectController.extend({
  name: '',
  code: '',
  description: ''
});

在这里看到一个工作jsbin

让我知道它是否有帮助。

于 2013-07-04T09:47:43.253 回答
0

The reason is your StockNewController extends Ember.ObjectController, which extends Ember.ObjectProxy.

Ember.ObjectProxy will delegate all of it’s unknown properties to the content object, with one exception. If we try to set a new property on a proxy while it’s content is undefined, we will get an exception.

Here you try to set the name property on the ObjectController, when it's content is undefined.

The simple solution will be to set the content before you set any other property. This can be done in the model hook itself.

App.StockNewRoute = Em.Route.extend({
  model: function() {
    return App.Stock.create();
  } 
});

For simplicity, I've updated the fiddle with a plain Ember.Object for the model.

You can get detailed info about ObjectProxy here

于 2013-07-04T17:42:28.933 回答