datapanda
datapanda

Reputation: 71

Ember.js Ways to Pass Dynamic Segment

Is there another way in Ember.js to pass the dynamic segment of a route that's not through the template? The application I'm building uses dynamic segments in, from my understanding, the traditional Ember way where it uses link-to through templates. However, I have a list of records that I'm bringing in and inserting through datatables in a single view. These records each have a link to "edit" them that is manually added as a field within the data. For example, array[0] = record_id, array[1] = some name, array[2] = Edit Record.

this.resource('editrecord', { path: 'forms/:form_id/:record_id/editrecord'});

Upvotes: 2

Views: 993

Answers (1)

Marcio Junior
Marcio Junior

Reputation: 19128

You can manually call a transition to route with transitionTo(routeName, segmentsValuesObject) inside of a route:

var formId = ...
var recordId = ..
this.transitionTo('editrecord', { form_id: formId, record_id: recordId })

or transitionToRoute(routeName, segmentsValuesObject) inside of a controller

var formId = ...
var recordId = ..
this.transitionToRoute('editrecord', { form_id: formId, record_id: recordId })

Each dynamic segment of the route, is represented by key value in segmentsValuesObject. Where the key is the name of the dynamic segment, and the value is the current value that will be represented in the url.

Here is a sample with this working http://jsbin.com/ucanam/1316

I hope it helps

Upvotes: 3

Related Questions