Ember.js 如何使用余烬数据加载嵌套记录(主详细记录)?

Ember.js 如何使用余烬数据加载嵌套记录(主详细记录)?,ember.js,ember-data,Ember.js,Ember Data,主记录、应用程序/模型/帐户: import DS from 'ember-data'; export default DS.Model.extend({ username: DS.attr('string'), emailaddress: DS.hasMany('emailaddresses'), birthdate: DS.attr('date'), gender: DS.attr('boolean') }); 详细记录、应用程序/型号/电子邮件地址: import DS

主记录、应用程序/模型/帐户:

import DS from 'ember-data';

export default DS.Model.extend({
  username: DS.attr('string'),
  emailaddress: DS.hasMany('emailaddresses'),
  birthdate: DS.attr('date'),
  gender: DS.attr('boolean')
});
详细记录、应用程序/型号/电子邮件地址:

import DS from 'ember-data';

export default DS.Model.extend({
  account: DS.belongsTo('account'),
  emailaddress: DS.attr('string'),
  verificationcode: DS.attr('string'),
  isverified: DS.attr('string')
});
来自服务器的伪JSON字符串:

{“id”:0,“用户名”:“ikevin”,“出生日期”:“2017年1月30日1:34:38” PM,“性别”:true,“电子邮件地址”:[{“id”:0,“电子邮件地址”:”aaa@bbb.com,“verificationcode”:“AAAAA”,“isverified”:false}]}

适配器/app/adapters/account.js

import ApplicationAdapter from './application';

export default ApplicationAdapter.extend({

  urlForQueryRecord(query) {
    if (query.profile) {
      delete query.profile;
      return `${this._super(...arguments)}/profile`;
    }

    return this._super(...arguments);
  }

});
路由app/route/index.js:

import Ember from 'ember';
import RSVP from 'rsvp';

export default Ember.Route.extend({
  model() {
    return RSVP.hash({
      walletbalance: this.get('store').queryRecord('wallet', {balance: true}),
      instagramfriendscount: this.get('store').queryRecord('instagram', {friendscount: true}),
      accountprofile: this.get('store').queryRecord('account', {profile: true})
    });
  }
});
以及app/templates/components/account-profile.hbs:

<div class="box">
  <div class="title">Your Profile</div>
  <div>Username: {{account.accountprofile.username}}</div>
  <div>Email Address: {{account.accountprofile.emailaddess}}</div>
  <div>Birthdate: {{account.accountprofile.birthdate}}</div>
  <div>Gender: {{account.accountprofile.gender}}</div>
</div>

你的个人资料
用户名:{{account.accountprofile.Username}
电子邮件地址:{{account.accountprofile.emailaddess}
生日:{{account.accountprofile.Birthdate}
性别:{{account.accountprofile.Gender}
我认为这里有两个问题:

  • 在Chrome Ember插件中,模型类型“emailaddress”的数据始终为0。所以,这意味着它没有加载

  • 在app/templates/components/account-profile.hbs中,{{account.accountprofile.emailaddess}}未引用正确的字段。注意:目前它预计只显示1个电子邮件地址

  • 如何解决这些问题以加载和显示嵌套记录


    谢谢

    是的,我自己解决了:

    我将其更改为嵌套数组(如下所述:)

    因此,从服务器返回的字符串变为:

    {“id”:0,“用户名”:“ikevin”,“出生日期”:“2017年1月30日2:01:14” PM,“性别”:true,“电子邮件地址”:[{“电子邮件地址”:”aaa@bbb.com,“verificationcode”:“AAAAA”,“isverified”:false}]}

    在哈佛商学院:

    <div>Email Address: {{account.accountprofile.emailaddresses.0.emailaddress}}</div>
    
    电子邮件地址:{{account.accountprofile.emailaddresses.0.emailaddress}
    
    它显示电子邮件地址

    谢谢

    我还删除了之前生成的“emailaddress”模型。