保存模型的记录在ember-data 1.0.0-beta.3中不起作用? [英] Save record of model is not working in ember-data 1.0.0-beta.3?

查看:100
本文介绍了保存模型的记录在ember-data 1.0.0-beta.3中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了什么 -

模型 -

App.Book = DS.Model.extend({
   book_name: DS.attr('string'),
   edition: DS.attr('string')
});

路由器 -

App.Router.map(function() {
   this.resource('books', function() {
      this.route('new');
   });
});


App.BooksNewRoute = Ember.Route.extend({
    model: function() {
        return this.store.createRecord('book');
    },

    actions: {
       save: function() {
          this.modelFor('newBook').save();
       }
    }
});

现在有人可以帮我..如何保存数据?

Now Can anybody help me.. How to save data ?

我收到错误,如

TypeError: this.modelFor(...) is undefined
this.modelFor('newBook').save();


推荐答案

我认为这应该有效。

App.BooksNewRoute = Ember.Route.extend({
    model: function() {
        return this.store.createRecord('book');
    },

    actions: {
       save: function() {
          this.get('model').save();  
       }
    }
});

这篇关于保存模型的记录在ember-data 1.0.0-beta.3中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆