belongsTo和hasMany未在模板

时间:2016-08-07 21:14:40

标签: ember.js ember-data

我有这些模特:

export default DS.Model.extend({
  uid: DS.attr('number'),
  name: DS.attr('string'),
  fullName: DS.attr('string'),
  description: DS.attr('string'),
  homepage: DS.attr('string'),
  owner: DS.attr('string'),
  private: DS.attr('boolean'),
  organization: DS.belongsTo('organization', { async: true })
});

export default DS.Model.extend({
  uid: DS.attr('number'),
  avatar: DS.attr('string'),
  blog: DS.attr('string'),
  company: DS.attr('string'),
  login: DS.attr('string'),
  location: DS.attr('string'),
  rooms: DS.hasMany('room', { async: true })
});
在Ember Inspector中我可以看到整个数据:

enter image description here

房间和组织

当我尝试在我的模板中显示它们时:

<div class="row">
    <ul id="room-list">
      {{#each model key="uid" as |room|}}
        <li>
          <label>{{room.uid}}: {{room.name}} ({{room.organization.name}}) </label>
        </li>
      {{/each}}
    </ul>
  </div>

组织名称所在的()为空,如53415342: PredictionIO-Enterprise ()

这是我的序列化程序

import DS from 'ember-data';
import Ember from 'ember';

export default DS.JSONSerializer.extend({
  primaryKey: 'uid'
});

我在/organizations/{uid}上的服务器响应是

{
  "uid": 1247016,
  "createdAt": 1470496909124,
  "name": "Tweek",
  "avatar": "https://avatars.githubusercontent.com/u/1247016?v=3",
  "blog": "http://tweek.tv",
  "company": null,
  "login": "Ubertweek",
  "location": "Berlin, Germany",
  ....

0 个答案:

没有答案