繁体   English   中英

余烬数据升级后无法创建记录

[英]Cannot create record after ember-data upgrade

最新的ember-data 1.0版本发布后,我在创建记录时遇到了一些问题。 我在发行说明中读过-https: //github.com/emberjs/data/blob/master/TRANSITION.md

App.NewPostRoute = Ember.Route.extend({
  model: function() {
    return App.Post.createRecord();
  }
});

现在被替换为:

App.NewPostRoute = Ember.Route.extend({
  model: function() {
    return this.store.createRecord('post');
  }
});

但是在我的控制器中,我无法弄清楚如何调用createRecord()方法,因为我有类似以下内容:

addNewTrip:function() {
    var tripDeparature = this.get("tripDeparature");
    var tripArrival = this.get("tripArrival");
    var trips = App.Trips.createRecord({
         tripDeparature: tripDeparature,
         tripArrival:tripArrival,
         isCompleted:false
    });
    trip.save();
    this.set("tripDeparture","");
    this.set("tripArrival","");
}

并且它引发一个错误:...没有方法'createRecord'(在新版本发布后会出现),但是我无法弄清楚如何正确调用createRecord。 任何帮助是极大的赞赏。

代替App.Trips.createRecord(parameters ...)使用this.store.createRecord('trips', parameters ...)

您的代码将变为:

addNewTrip:function() {
    var tripDeparature = this.get("tripDeparature");
    var tripArrival = this.get("tripArrival");
    var trip = this.store.createRecord('trips', {
         tripDeparature: tripDeparature,
         tripArrival:tripArrival,
         isCompleted:false
    });
    trip.save();
    this.set("tripDeparture","");
    this.set("tripArrival","");
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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