Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4828

Model doesn't refresh when I transition to it in ember 2.2.0

$
0
0

@samtes wrote:

// app/routes/questions.js

import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';

export default Ember.Route.extend(AuthenticatedRouteMixin, {
  correct: "",
  wrong: "",
  model () {
    return this.store.find("question").then(questions => {
      return this.store.find("key", this.get("session.data.authenticated.key")).then(key => {
        this.set("correct", key.get("correct"));
        this.set("wrong", key.get("wrong"));
        return key.get("questions");
      });
    });
  },

 afterModel (model, transition) {
    this.controllerFor("question").set("key", this.get("session.data.authenticated.key"));
    model = model.filter(item => {
     return  this.get("correct").indexOf(item.id) === -1 && this.get("wrong").indexOf(item.id) === -1;
    });
    this.transitionTo("question", model.get("firstObject"));
  }
});

//app/routes/question.js

import Ember from 'ember';

export default Ember.Route.extend({
  model (params) {
    return this.store.find("question", params.question_id);
  },

  setupController (controller, model) {
    controller.set("model", model);
  }
});

//app/controllers/question.js

import Ember from 'ember';

export default Ember.Controller.extend({
  key: "",
  option: "",
  actions: {
    submitQuiz () {
         this.store.findRecord("key", this.get("key")).then(key => {
        key.set("answer", this.get("option"));
        key.save();
      }).then(() => {
        this.transitionToRoute("questions");
      });
    },

    selected (option, elm) {
      this.set("option", option);
      Ember.$(".question_container").find(".selected").removeClass("selected");
      Ember.$("#".concat(elm)).addClass("selected");
    }
  }
});

However, this.transitionToRoute("questions") in app/controllers/questions.js doesn't refresh model in app/routes/questions until I actually reload the page. * I have also tried this.transitionTo("questions"); What am I doing wrong??

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles