0

所以,我的createCharacter控制器中有一个方法。它主要工作,但是当我尝试在 a 中填充一个 hasMany 字段时forEach,我得到一个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();
}

我究竟做错了什么?

4

0 回答 0