且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

未捕获错误:断言失败:您不能将`id`设置为模型的属性

更新时间:2022-10-15 16:32:49

只需从 DS.Model $中省略 id C $ C>。 Ember数据自动为您处理。您仍然可以使用id查找记录,并且当您从Ember应用程序中访问该对象时,它将是对象上的一个属性。 请参阅这里 here 获取更多信息。

Just leave out the id attribute from your DS.Model. Ember-data automatically handles that for you. You'll still be able to find the record using the id, and it'll be a property on the object when you access it from within your Ember application. See here and here for more info.

App.Plan = DS.Model.extend({
  name: DS.attr('string'),
  period: DS.attr('number'),
  price: DS.attr('number')
});