将关系数据绑定到ember.js中的视图

将关系数据绑定到ember.js中的视图,ember.js,ember-data,Ember.js,Ember Data,我有两种模式:公司和个人。一个公司有很多人,一个人属于一个公司。我试图在UI中表示这一点。不过,我很难弄清楚如何将关系数据绑定到视图 这是我的个人模型 App.Person = DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), city: DS.attr('string'), state: DS.attr('string'), email: DS.attr('st

我有两种模式:公司个人。一个公司有很多人,一个人属于一个公司。我试图在UI中表示这一点。不过,我很难弄清楚如何将关系数据绑定到视图

这是我的个人模型

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>

名字
{{input type=“text”value=firstName class=“form control”id=“firstName”占位符=“First Name”}
姓
{{input type=“text”value=lastName class=“form control”id=“lastName”placeholder=“Last Name”}
电子邮件地址
{{input type=“email”value=email class=“form control”id=“email”placeholder=“email”}
城市
{{input type=“text”value=city class=“form control”id=“city”placeholder=“city”}
陈述
{{input type=“text”value=state class=“form control”id=“state”placeholder=“state”}
单位
{{company.name}
多恩

但是,从未向
公司/2
发出请求。我是否需要在路由器中返回此人及其公司的RSVP哈希以适应此情况


这是从
/people/
返回的json,如果您正在使用
RESTAdapter
您需要将
公司id:“1”
更改为
公司:“1”

您的示例似乎是正确的,您可以显示从服务器返回的json吗?当然,在我进入单记录路径之前,我会得到一份人员列表。这是我回答您的问题时返回的json,我认为您的问题在于您的公司财产名称。如果将rails与活动模型序列化程序一起使用,则可以使用
DS.ActiveModelAdapter