Note that there are some explanatory texts on larger screens.

plurals
  1. POEmber.js: how to use a parent model's property in a url path?
    primarykey
    data
    text
    <p>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?</p> <p>For example, I have a model and some data like this:</p> <pre><code>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 } ] }] </code></pre> <p>And here are my routes:</p> <pre><code>App.Router.map(function() { this.resource('current-suggestions'); this.resource('suggestion', { path: '/current-suggestions/:suggestion_id' }); }); </code></pre> <p>My template is like this:</p> <pre><code>{{#each model}} &lt;td&gt; &lt;ul&gt; {{#each suggestions}} &lt;li class="suggestion"&gt; &lt;h3&gt; {{#linkTo 'suggestion' this}}{{title}}{{/linkTo}} &lt;/h3&gt; &lt;/li&gt; {{/each}} &lt;/ul&gt; &lt;/td&gt; {{/each}} </code></pre> <p>So, at the moment my paths are <code>current-suggestions/1</code>. But what I'd like to do is have paths such as <code>current-suggestions/Start/1</code>. So, the path is generated using a property from the parent model.</p> <p>Is it possible to do something like this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload