Emberjs:无法使用Ember Data 1.0.0测试版创建记录 [英] Emberjs: Cannot createRecord with Ember Data 1.0.0 beta

查看:81
本文介绍了Emberjs:无法使用Ember Data 1.0.0测试版创建记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序可以保存多个任务列表。每个任务列表都有多个任务。每个任务都有多个注释。



更新到新的Ember Data之后,我不得不删除我的创建纪录。目前我有这个,这不行。虽然它没有任何错误,我的模型似乎没有更新。

  App.TaskController = Ember.ArrayController。扩展({
需要:['list'],
isEditing:false,
actions:{
addTask:function(){
var foo = this.store .createRecord('task',{
description:'',
list:this.get('content.id'),
comments:[]
});
foo.save();
console.log('Task Created!');
},
edit:function(){
this.set('isEditing ',true);
},
doneEditing:function(){
this.set('isEditing',false);
}
}
});有谁知道如何创建一个新的任务(以及如何创建新的注释)在这个上下文?



请参阅这里的小提琴: http:// jsfiddle .net / edchao / W6QWj /

解决方案

好的,所以我回答了我自己的问题。我缺少pushObject()方法。这是另一种做事的方法。虽然我不知道这是否是最佳做法,因为它会抛出错误断言失败:您只能在此关系中添加列表记录

  App.ListController = Ember.ObjectController.extend({
actions:{
addTask:function(){
var foo = this.store.createRecord('任务',{
描述:'',
列表:this.get('content.id'),
评论:[]
});
这个.get('tasks')。pushObject(foo);
foo.save();
}
}
});


I have an app that keeps multiple task lists. Each task list has multiple tasks. Each task has multiple comments.

After updating to the new Ember Data, I had to scrap my record creation code. Currently I have this, which doesn't work. Though it doesn't throw any errors, my model does not seem to be updating.

App.TaskController = Ember.ArrayController.extend({
  needs : ['list'],
  isEditing : false,
  actions : {
    addTask : function(){
      var foo = this.store.createRecord('task', { 
        description : '',
        list : this.get('content.id'),
        comments : []  
      });
      foo.save();
      console.log('Task Created!');
    },
    edit : function(){
        this.set('isEditing', true);
    },
    doneEditing : function(){
        this.set('isEditing', false);
    }
  }
});

Does anyone know how to create a new task (as well as how to create new comments) in this context?

See fiddle here : http://jsfiddle.net/edchao/W6QWj/

解决方案

Okay, so I've answered my own question. I was missing the pushObject() method. Here is another way to do things. Although I'm not sure if it's the best practice since it does throw the error "Assertion failed: You can only add a 'list' record to this relationship "

App.ListController = Ember.ObjectController.extend({
  actions:{
    addTask : function(){
      var foo = this.store.createRecord('task', { 
        description : '',
        list : this.get('content.id'),
        comments : []  
      });
      this.get('tasks').pushObject(foo);
      foo.save();
    }
  }
});

这篇关于Emberjs:无法使用Ember Data 1.0.0测试版创建记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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