Note that there are some explanatory texts on larger screens.

plurals
  1. PObind relational data to view in ember.js
    primarykey
    data
    text
    <p>I have two models: <strong>Company</strong> and <strong>Person</strong>. A company has many people and a person belongs to a company. I'm trying to represent this in the UI. I'm having a hard time figuring out how to bind relational data to the view though. </p> <p>Here is my Person model </p> <pre><code>App.Person = DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), city: DS.attr('string'), state: DS.attr('string'), email: DS.attr('string'), company: DS.belongsTo('company'), fullName: function() { return this.get('firstName') + ' ' + this.get('lastName'); }.property('firstName', 'lastName') }); </code></pre> <p>Here is my Company model</p> <pre><code>App.Company = DS.Model.extend({ name: DS.attr('string'), people: DS.hasMany('person') }); </code></pre> <p>Here is my route</p> <pre><code>App.Router.map(function() { this.resource('people', function() { this.resource('person', { path: ':person_id'}); this.route('new'); }); }); App.PersonRoute = Ember.Route.extend({ model: function(params) { return this.store.find('person', params.person_id); } }); </code></pre> <p>And here is my view</p> <pre><code>&lt;script type="text/x-handlebars" data-template-name='show/_edit'&gt; &lt;div&gt; &lt;form role="form"&gt; &lt;div class="form-group"&gt; &lt;label for="firstName"&gt;First Name&lt;/label&gt; {{input type="text" value=firstName class="form-control" id="firstName" placeholder="First Name"}} &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label for="lastName"&gt;Last Name&lt;/label&gt; {{input type="text" value=lastName class="form-control" id="lastName" placeholder="Last Name"}} &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label for="email"&gt;Email address&lt;/label&gt; {{input type="email" value=email class="form-control" id="email" placeholder="Email"}} &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label for="city"&gt;City&lt;/label&gt; {{input type="text" value=city class="form-control" id="city" placeholder="City"}} &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label for="state"&gt;State&lt;/label&gt; {{input type="text" value=state class="form-control" id="state" placeholder="state"}} &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label for="company"&gt;Company&lt;/label&gt; &lt;span&gt;{{company.name}}&lt;/span&gt; &lt;/div&gt; &lt;button type="submit" class="btn btn-default" {{action 'doneEditing'}}&gt;Done&lt;/button&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p></p> <p>A request is never issued to <code>companies/2</code> though. Do i need to return an RSVP hash of both the person and their company in the router to accommodate this? </p> <p>Here is the returned json from <code>/people/</code> <a href="https://gist.github.com/anonymous/7632294" rel="nofollow">https://gist.github.com/anonymous/7632294</a></p>
    singulars
    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