dimanche 31 mai 2015

Ember-cli unable to access dynamic routes model

Router.map(function() {
  this.route('projects',     function() {
    this.route('project', { path: '/:project_id' }, function() {
        this.route('cards');
        this.route('new',{ path: '/cards/new' });
    });
  });
});

Forder structure: app

   --/routes
     --/projects
       --/project.js   
       --/project
           --/cards.js
           --/new.js

I can access the dynamic segment :project_id in cards.js route like this

import Ember from 'ember';

export default Ember.Route.extend({
  model: function(){
    var project = this.modelFor('projects/project');
    return project.get('cards');
  }
});

but same code is not working for route new.js i.e not able to access project model

import Ember from 'ember';

export default Ember.Route.extend({
    actions: {
        addCard: function() {
            var project = this.modelFor('projects/project');
            console.log(project); //this is printing projects array I was expecting single current project model
        }
    }
});

//my project route looks something like this

import Ember from 'ember';

export default Ember.Route.extend({
    setupController: function(controller,model) {
        this._super(controller, model);
        controller.set('projectList',this.store.find('project'));
    },  
    model:function(params) {
        return this.store.find('project',params.project_id);
    }

});




Aucun commentaire:

Enregistrer un commentaire