jeudi 25 février 2016

Set multiple models in render function, with the possibility to observe, reboot and save each separately

i have a problem with Ember.RSVP.hash(). Models does not render in templates, observes not work with promise model, and promise does not function reload().

import Ember from 'ember';

export default Ember.Route.extend({     
  achievementMode: true,
  params:[],
  model(params){
    this.set('params', params);
    return params;
  },
  renderTemplate(controller, model){
    var firstController = this.controllerFor('clients/'+model.first),
        secondController = this.controllerFor('clients/'+model.second),
        firstModel = this.getModel(model.first,model),
        secondModel = this.getModel(model.second,model);

    this.render('clients/'+model.first,{
      outlet:'first',
      controller:firstController,
      model: Ember.RSVP.hash(firstModel)
    });
    this.render('clients/'+model.second,{
      outlet:'second',
      controller:secondController,
      model: Ember.RSVP.hash(secondModel)
    });
  },
  setupController: function(controller, model) {
    this._super(controller, model);
    this.controllerFor('clients').set('firstBlock', model.first);
    this.controllerFor('clients').set('secondBlock', model.second);
  },
  getModel(modelName, params){
    var model = {};
    if(modelName === 'profile'){
      model ['client'] = this.store.findRecord('user', params.user_id, { reload: true }),
      model ['achievements'] = this.store.query('achievement', {'mode':this.get('achievementMode'),'user':params.user_id})
    }
    model ['params'] = params;
    return model;
  }
});

Have a rest adapter, and after request observes('params') not work, and params not render in template.

{{#each achievements as |achievement|}}
test
{{/each}}

and promise not have a function reload(). ember 2.2 any thoughts? how to implement plans?




Aucun commentaire:

Enregistrer un commentaire