替换.get(“transaction”)。commit()

时间:2013-12-03 13:14:05

标签: javascript ember.js ember-data single-page-application

我正在关注模型changedFavorite中包含方法的旧教程:

App.Bookmark = DS.Model.extend({
    title: DS.attr('string'),
    url: DS.attr('string'),
    favorite: DS.attr('boolean'),

    changedFavorite: function(){
        this.get("transaction").commit();
        console.log("favorite changed");
        }.observes("favorite")
});

我收到错误TypeError: Cannot call method 'commit' of null

当勾选模板中的复选框时,应该调用该方法:

{{view Ember.Checkbox checkedBinding="favorite"}}

this.get("transaction").commit();view Ember.checkbox的替换代码吗?

1 个答案:

答案 0 :(得分:1)

现在你必须使用save()

App.Bookmark = DS.Model.extend({
    title: DS.attr('string'),
    url: DS.attr('string'),
    favorite: DS.attr('boolean'),

    changedFavorite: function(){
        this.save();
        console.log("favorite changed");
    }.observes("favorite")
});