简体   繁体   中英

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:

post.deleteRecord();    
post.get('isDeleted');   
post.store.save();

My adapter-settings: 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:

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. My current versions are (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

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
I have made a fiddle, here

Solution 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 . I have made a working example on Fiddle: here

You should use post.save(); not post.store.save();

also post.destroyRecord(); should work.

Do you get Uncaught TypeError: undefined is not a function with those calls?

if so, can you show a more complete stack trace?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM