1

我正在开发一个练习应用程序,它会一个一个地向用户显示问题。当用户解决一个问题时,他会转到下一个问题。问题可以是不同的类型(例如多项选择、连接匹配等)。每个问题都有一个用于呈现它的首选视图。当一个问题被回答时,它的属性finished设置为true。我观察到该属性已从其问题视图中的问题完成,并且当设置为 true 时,视图会自动向用户显示正确答案。

当用户点击浏览器后退按钮返回上一个问题时,路由中的 setup-controller 方法将被执行,其中当前模型设置为前一个模型。该模型上的观察者看到问题已完成并尝试显示正确答案,但视图尚未更改。

所以会发生什么是匹配问题试图在画布元素上绘制点和线以在多选视图中显示答案(没有画布......)

我希望后退按钮可以工作,这样用户就可以返回查看他提出的问题是对是错,并查看解决方案。

显然,我的流程有问题,但我看不出我到底需要改变什么

这是我的路由器代码:

// Player.EI is my exercise instance, 
// an Ember Exercise class which has questions, holds score, etc... 

Player.Router.map(function() {
    this.resource('index', {path: "/"});
    this.resource('question', {path: "question/:question_id"});
});

Player.IndexRoute = Em.Route.extend({
    setupController: function(controller, model){
        this.controllerFor('application').loadExerciseData(); //from xml file
    }
});

Player.QuestionRoute = Em.Route.extend({
    beforeModel: function(transition){
        if(undefined === Player.EI){
            this.controllerFor('application').loadExerciseData(transition.params.question_id);
            transition.abort();
            return;
        }
    },
    afterModel: function(model, transition){
        Player.EI.setCurrent(model);
    }, 
    setupController: function(controller, model){
        // the dock is a panel at the bottom of the application, 
        // with buttons to submit and navigate

        d = this.controllerFor('dock');
        d.set('currentQuestion', Player.EI.getCurrent());
        d.set('next', Player.EI.getNext());
        d.set('previous', Player.EI.getPrevious());
        d.set('elements', Player.EI.getElements());

        cn = this.controllerFor(model.getController());

        //this causes the views to do DOM-actions, while in the wrong template
        cn.set('content', model); 

        //do init stuff with the question, like play audio
        cn.enter(); 

        //add a reference to the dock in the controller
        cn.set('dock', d);

        //add a reference to the controller in the dock
        d.set('currentQuestionController', cn);
    },
    renderTemplate: function(controller, model) {

        this.render('stage'); 

        this.render('dock', {
            outlet: 'dock'
        });

        //each question can tell what controller it needs
        cn = this.controllerFor(model.getController(), model);

        //each question can tell what view it needs to display it
        this.render(model.getPreferredTemplate(), {
            into: 'stage',
            outlet: 'question',
            controller: cn,
            content: model
        });

        //Exercise title,...
        this.render("exerciseinfo", {
            into: 'stage',
            outlet: 'exerciseinfo',
            controller: cn,
            content: model
        });
    }, 
    model: function(param, transition){
        return Player.EI.getElement(param.question_id); 
    }
});
4

0 回答 0