所以,我的控制器中有一个createCharacter
方法。它主要起作用,但是当我尝试在forEach
中填充hasMany字段时,出现attempted to handle event 'loadedData'...
错误。有人说数据是空中的。一个人说是未提交的(我试着做store.commit()
。这就是当错误切换到飞行时)。
这是有问题的方法。其他任何东西都不应该编辑或写入或读取这些记录(我至少知道):
createCharacter: function(){
var character = App.Character.createRecord({
isEditing: true,
(...)
});
//Broken
App.Skill.find().forEach(function(item, index){
console.log(item.get('id'));
var newSkill = character.get('skills').createRecord({
rank: 0,
skill: item
});
//newSkill.save();
});
/*//Works (but doesn't make all the records I need)
character.get('skills').createRecord({
rank: 0,
skill: App.Skill.find(1)
});
*/
/*this part is because I can't figure out how to filter records from a hasMany property. Not entirely relevant to the aforementioned issue, but it has the same problem when it's uncommented.
var skills = character.get('skills');
var skillsList = App.Skill.find().getEach('id');
$.each(skillsList, function(index, value){
var rankID = skills.createRecord({
rank: 0,
skill: App.Skill.find(value),
});
switch(App.Skill.find(value).get('type')){
case 1:
character.get('generalSkills').addObject(rankID);
break;
case 2:
character.get('combatSkills').addObject(rankID);
break;
case 3:
character.get('knowledgeSkills').addObject(rankID);
break;
}
});*/
character.save();
}
我做错了什么?