In Ember.js if you have a model that has a one-to-many relationship is it possible to generate links based on a property of the parent model?
For example, I have a model and some data like this:
var SuggestionGroup = Ember.Model.extend({
id: Ember.attr('number'),
name: Ember.attr('string'),
suggestions: Ember.hasMany('App.Suggestion', {
key: 'suggestions',
embedded: true
})
});
SuggestionGroup.adapter = Ember.FixtureAdapter.create();
SuggestionGroup.FIXTURES = [
{
id: 1,
name: 'Start',
suggestions: [
{
id: 1,
title: 'Fetching coffee and cake for the Interface Developers',
description: 'Because they\'re so brilliant',
upVotes: 10,
downVotes: 2
},
{
id: 2,
title: 'Criticising the app devs more',
description: 'They enjoy a bit of banter',
upVotes: 8,
downVotes: 4
},
{
id: 3,
title: 'Not updating JIRA',
description: 'It\'ll be funny when the PMs start raging',
upVotes: 1000000,
downVotes: 0
}
]
}]
And here are my routes:
App.Router.map(function() {
this.resource('current-suggestions');
this.resource('suggestion', {
path: '/current-suggestions/:suggestion_id'
});
});
My template is like this:
{{#each model}}
<td>
<ul>
{{#each suggestions}}
<li class="suggestion">
<h3>
{{#linkTo 'suggestion' this}}{{title}}{{/linkTo}}
</h3>
</li>
{{/each}}
</ul>
</td>
{{/each}}
So, at the moment my paths are current-suggestions/1
. But what I'd like to do is have paths such as current-suggestions/Start/1
. So, the path is generated using a property from the parent model.
Is it possible to do something like this?