[英]EmberJS throws undefined after deleteRecord and save
Solution on last section of this question. 最后一个问题的解决方案。
After six hours... I can't delete an ember-data object without errors. 六个小时后...我无法删除没有余烬数据的对象。 I've followed the starter video-tutorial .
我已经看了入门视频教程 。 For deletion the ember-docs suggests the following steps:
对于删除,ember-docs建议执行以下步骤:
post.deleteRecord();
post.get('isDeleted');
post.store.save();
My adapter-settings: App.ApplicationAdapter = DS.FixtureAdapter;
我的适配器设置:
App.ApplicationAdapter = DS.FixtureAdapter;
App.ApplicationRoute = Ember.Route.extend({
model: function () {
this.store.find('post', 1).then(function (post) {
// success
console.log(post.get('title'));
post.deleteRecord();
post.get('isDeleted');
post.store.save(); <--------- ERROR, same with post.save()
// App.store.commit();
}, function (error) {
// error handling
console.log(error);
});
EmberJS complains: Uncaught TypeError: undefined is not a function I've tried serveral modifications: EmberJS抱怨: Uncaught TypeError:undefined不是我尝试过服务器修改的函数 :
post.deleteRecord();
post.get('isDeleted');
App.store.commit();
and: 和:
post.destroyRecord();
I've changed the EmberJS, Ember-Data and HandleBars versions, and I've switched between cdn and grunt. 我更改了EmberJS,Ember-Data和HandleBars版本,并在cdn和grunt之间切换。 My current versions are (bower.json):
我当前的版本是(bower.json):
"ember": "1.9.0",
"handlebars": "2.0.0",
"ember-data": "1.0.0-beta.8",
The postmodel and postfixtures looks like this: 后模型和后缀如下所示:
App.Post = DS.Model.extend({
titel : DS.attr('string'),
bericht: DS.attr('string')
});
App.Post.FIXTURES = [
{ id: 1, titel: 'titel 1', bericht: 'bericht 1' ,},
{ id: 2, titel: 'titel 2', bericht: 'bericht 2' },
{ id: 3, titel: 'titel 3', bericht: 'bericht 3' }
];
UPDATE 1 更新1
Stacktrace 堆栈跟踪
Uncaught TypeError: undefined is not a function ember.prod.js:15469
(anonymous function) ember.prod.js:10127
Cache.get ember.prod.js:15509
isPath ember.prod.js:16307
get bower_components.js:8 Ember.Object.extend.serializeAttribute bower_components.js:8
(anonymous function) bower_components.js:9
(anonymous function) ember.prod.js:14209
Map.forEach.cb ember.prod.js:14007
OrderedSet.forEach ember.prod.js:14217
Map.forEach bower_components.js:9
g.reopenClass.eachAttribute bower_components.js:9
g.reopen.eachAttribute bower_components.js:8
Ember.Object.extend.serialize bower_components.js:8
g.extend.mockJSON bower_components.js:8
g.extend.deleteRecord bower_components.js:9
v bower_components.js:10
(anonymous function) ember.prod.js:12273
forEach bower_components.js:10 Ember.Object.extend.flushPendingSave ember.prod.js:854
Queue.invoke ember.prod.js:919
Queue.flush ember.prod.js:724
DeferredActionQueues.flush ember.prod.js:149
Backburner.end ember.prod.js:204
Backburner.runember. prod.js:586
executeTimersember. prod.js:575
(anonymous function) ember.prod.js:575
Update 2 更新2
I have made a fiddle, here 我在这里摆弄
Solution 3 解决方案3
Probably, the problem was caused by version hell. 该问题可能是由版本地狱引起的。 I have changed ember-data 1.0.0-beta.8 to ember-data 1.0.0-beta.12 .
我已经将ember-data 1.0.0-beta.8更改为ember-data 1.0.0-beta.12。 I have made a working example on Fiddle: here
我在Fiddle上做了一个工作示例: 这里
You should use post.save();
您应该使用
post.save();
not post.store.save();
不是
post.store.save();
also post.destroyRecord();
还
post.destroyRecord();
should work. 应该管用。
Do you get Uncaught TypeError: undefined is not a function with those calls? 您是否收到Uncaught TypeError:undefined不是具有这些调用的函数 ?
if so, can you show a more complete stack trace? 如果是这样,您可以显示更完整的堆栈跟踪吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.