jeudi 30 juillet 2015

Overriding parent model loading in nested Ember.js route

I'm learning Ember and trying to figure how to do a signup form.

I have a /users route from before and I have created a users/new route. In my users route I load all the users from the store - and now my users/new route will load all the users - which is not really needed.

Should I create a separate users/index.js route for the index or is there another way to override the parent model loading that I should be using?

// app/router.js
import Ember from 'ember';
import config from './config/environment';

var Router = Ember.Router.extend({
  location: config.locationType
});

Router.map(function() {
  this.resource('users', function() {
    this.route('new');
  });

  this.route('users', function() {
    this.route('new');
  });
});

export default Router;


// routes/users.js
import Ember from 'ember';

export default Ember.Route.extend({
  model: function(){
    return this.store.findAll('user');
  }
});


// routes/users/new.js
import Ember from 'ember';

export default Ember.Route.extend({
  model: function(){
    return this.store.createRecord('user');
  }
});




Aucun commentaire:

Enregistrer un commentaire