Ember cli被新发布的ember数据破坏了吗?

时间:2015-03-14 18:24:46

标签: javascript ember.js ember-data firebase ember-cli

嗨,我是一个余烬菜鸟,当我升级到最新的余烬数据时,我收到了这些警告:

更新:我的应用程序有两个版本,一个没有ember-cli,另一个带有ember cli,两个应用程序完全相同,它们都将这些消息记录到控制台:

弃用:不推荐使用snapshot.constructor,而是使用snapshot.type

弃用:不推荐使用DS.Snapshot.get()。请改用.attr(),. belongsTo()或.hasMany()。

第一个弹出两次,第二个弹出一次,我点击警报后就是代码:

不同之处在于没有使用ember-cli构建的应用程序可以使用!

在我看来,这一定是ember-cli的问题

import Ember from 'ember';

export default Ember.Controller.extend({
    sortProperties:["time"],
    sortAscending:true,
    start:new Date(),
    count:0,
    incorrect:0,
    startReview:true,
    showHighScores:false,

    actions:{

        startReview:function(){
            this.set('startReview',false);
            this.set("showHighScores",false);
            this.start = new Date();
            this.count = 0;
            this.incorrect = 0;
            console.log(this.count);
        },

        showHighScores:function(){
            this.toggleProperty("showHighScores");
        },

        checkCorrectness:function(word){
            var textArray = this.get("model.text").split(" ");
            var length = textArray.length;
            if(word === textArray[this.count]){ 
                console.log("correct");
                this.count++;
                console.log(this.count);
            }else{
                console.log("Incorrect");
                this.incorrect++;
            }
            if(length === this.count){
                var finish = new Date();
                var time = finish-this.start;
                var accuracy = (this.count/(this.count+this.incorrect)*100);
                **alert("You took "+time/1000+" seconds! With "+accuracy+"% accuracy!");**
  

点击此提示后,会出现弃用警告

                this.saveResult(time);
                this.set('startReview',true);
            }
        },
    },
  

我认为以下代码中的设置和输入必须是违规者,但我   不知道怎么用最新的更新来改变它们   余烬数据

    randomizer:function(){
        this.set("randomArray",this.get("model.text").split(" ").randomize());      
    }.observes("startReview"),

    saveResult:function(timeTaken){
        var date = new Date(),
            userName = "TimTheGreat";


        var score = this.store.createRecord('score',{
            userName:userName,
            date:date,
            time:timeTaken,
            verse:this.get('model'),
        });

        var controller = this;
        var scores = controller.get("model.scores");
        score.save().then(function(score){
            scores.addObject(score).then(function(){
                controller.get("model").save();
            });

        });
    }
});

关于发布最新版本的ember-data http://emberjs.com/blog/2015/02/14/ember-data-1-0-beta-15-released.html

的博客文章链接

1 个答案:

答案 0 :(得分:2)

无法看到整件事情,很难看出问题所在。

如果有任何帮助,我遇到了类似的问题,因为我创建了自定义序列化程序(你为ember数据15 beta链接的注释特别指出更改是作用于序列化程序)和我的内部过度使用的序列化程序代码我正在做record.get(' someproperty')而不是他们希望你现在做的更新的record.attr(' someproperty')。

您是在推出自己的适配器/序列化器还是使用别人放在一起的东西?完全可能的是,无论你在哪里使用它都没有得到适当的更新。

更新: 根据评论,你正在使用firebase适配器,它显然有一个已知问题的ember数据0.1.15b。见https://github.com/firebase/emberfire/issues/226

基本上,他们正在使用:

json[payloadKey] = Ember.A(record.get(key)).mapBy('id'); 在他们的serializeHasMany函数中,它现在应该读取: json[payloadKey] = Ember.A(record.attr(key)).mapBy('id');