ember.js - Ember JS routing with multiple params -
i working on learning how work ember js , have run issue.
i have been developing simple application allows users add/edit/delete books library , search books based on either title or author. based on attempting create link-to render "/search/title/adventures_of_huckleberry_finn" tell router filter model returns books title equals "adventures of huckleberry finn" (i know i'll need string formating character case , replacing spaces underscores url, i'm not worried that).
i have following link-to in template (the title hard coded simplify testing)
{{#link-to "books.search" "title" "adventures_of_huckleberry_finn"}}search title{{/link-to}} i have following route defined (i suspect need nest second dynamic segment i'm not sure how since don't want new controller/route involved)
books.router.map(function () { this.resource('books', { path: '/' }, function () { this.route('search', { path: 'search/:search_by/:keyword' }); }); }); <!-- ... additional lines truncated brevity ... --> books.bookssearchroute = ember.route.extend({ model: function (params) { return this.store.filter('book', function (book) { return book.get(params.search_by) == params.keyword; }) }, rendertemplate: function (controller) { this.render('books/index', { controller: controller }); } }); now if hard code value or either :searchby or :keyword parms in bookssearchroute works fine, when attempt dynamicly pass both params following error:
more context objects passed there dynamic segments route: books.search
how can update route allows me pass both dynamic params bookssearchroute correctly?
here's general concept, use route dummy route used composite key. i'd still prefer joining key dash or , using single route, hey, here's how work.
app.router.map(function() { this.resource('colorwrap', {path:'/:pk1'}, function(){ this.resource('color', {path: '/:pk2'}); }); }); app.colorwraproute = ember.route.extend({ model: function(params) { return {pk1:params.pk1}; } }); app.colorroute = ember.route.extend({ model: function(params) { var wrapmodel = this.modelfor('colorwrap'); return $.getjson('/colors/' + wrapmodel.pk1 + '/' + params.pk2); } }); {{link-to 'click see red color!' 'color' 1 2}}
Comments
Post a Comment