У меня есть две модели: Компания и Человек. В компании много людей, и человек принадлежит компании. Я пытаюсь представить это в пользовательском интерфейсе. Однако мне трудно понять, как связать реляционные данные с представлением.
Вот моя модель человека
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')
});
Вот моя модель компании
App.Company = DS.Model.extend({
name: DS.attr('string'),
people: DS.hasMany('person')
});
Вот мой маршрут
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);
}
});
А вот мой взгляд
<script type="text/x-handlebars" data-template-name='show/_edit'>
<div>
<form role="form">
<div class="form-group">
<label for="firstName">First Name</label>
{{input type="text" value=firstName class="form-control" id="firstName" placeholder="First Name"}}
</div>
<div class="form-group">
<label for="lastName">Last Name</label>
{{input type="text" value=lastName class="form-control" id="lastName" placeholder="Last Name"}}
</div>
<div class="form-group">
<label for="email">Email address</label>
{{input type="email" value=email class="form-control" id="email" placeholder="Email"}}
</div>
<div class="form-group">
<label for="city">City</label>
{{input type="text" value=city class="form-control" id="city" placeholder="City"}}
</div>
<div class="form-group">
<label for="state">State</label>
{{input type="text" value=state class="form-control" id="state" placeholder="state"}}
</div>
<div class="form-group">
<label for="company">Company</label>
<span>{{company.name}}</span>
</div>
<button type="submit" class="btn btn-default" {{action 'doneEditing'}}>Done</button>
</form>
</div>
A request is never issued to companies/2
though. Do i need to return an RSVP hash of both the person and their company in the router to accommodate this?
Вот возвращенный json из /people/
https://gist.github.com/anonymous/7632294.
DS.ActiveModelAdapter
. - person Marcio Junior   schedule 25.11.2013