我是一个 ember 菜鸟,我最初在没有 ember-cli 的情况下构建了我的应用程序,它工作得很好,然后我想到了用 ember-cli 重建我非常简单的应用程序的好主意,这可能会出错:)
在 ember 抛出错误并将我指向我的 verse 控制器中的第 52 行之前,这两个应用程序中的一切都相同。请记住,该文件在我的非 ember-cli 版本中完全相同
更新我只是在第 52 行的位置放了很多空格,现在它说错误在第 53 行,它是空的:(((
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;
console.log(this.array);
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"),**//The offending line
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();
});
});
}
});