ember.js - Ember Router transitionTo nested route with params -
app.router.map(function() { this.resource('documents', { path: '/documents' }, function() { this.route('edit', { path: ':document_id/edit' }); }); this.resource('documentsfiltered', { path: '/documents/:type_id' }, function() { this.route('edit', { path: ':document_id/edit' }); this.route('new'); }); });
and controller subview event transitions filtered document
app.documentscontroller = ember.arraycontroller.extend({ subview: function(context) { ember.run.next(this, function() { //window.location.hash = '#/documents/'+context.id; return this.transitionto('documentsfiltered', context); }); }, });
my problem code works fine when hash of page changed.
but when run above code not w/ location.hash bit , w/ ember native transitionto
cryptic
uncaught typeerror: object [object object] has no method 'slice'
any clues?
thanks
update:
app.documentsfilteredroute = ember.route.extend({ model: function(params) { return app.document.find({type_id: params.type_id}); }, }); {{#collection contentbinding="documents" tagname="ul" class="content-nav"}} <li {{action subview this}}>{{this.nameoftype}}</li> {{/collection}}
the problem model hook returning array, while in transitionto using single object. rule of thumb calls transitionto should pass same data structure returned model hook. following rule of thumb recommend following:
app.documentscontroller = ember.arraycontroller.extend({ subview: function(document) { var documents = app.document.find({type_id: document.get("typeid")}); ember.run.next(this, function() { return this.transitionto('documentsfiltered', documents); }); } });
note: assume type_id stored in attribute typeid. maybe need adapt according needs.
Comments
Post a Comment