试图弄清楚如何使用关系,它只是不起作用。
// Data
{
"apps": {
"-AFCH5-Kvkc_nfQxnpZ8": {
"name": "Leap Day",
"playLink": "https://play.google.com/store/apps/details?id=com.nitrome.leapday",
"price": "0.00",
"like": 0,
"show": "-SFCH5-Kvkc_nfQxnpZ8",
"provider": "-PFCH5-Kvkc_nfQxnpZ8",
"imageUrl": "https://www.google.com/url?q=https://lh3.googleusercontent.com/5oR-jbrmKNWqdWQnwrDjPD2PJUJekGK_BUAQOjKD3GuJRTk2MLVzuU2HJ0wyY2BYPsdS%3Dw300-rw&sa=D&ust=1464126095843000&usg=AFQjCNH0RSH6_0bA_EUqnZaldtUxCH1fAw"
},
"-AFCH5-Kvkc_nfQxnpZ9": {
"name": "Gangfort",
"playLink": "https://www.google.com/url?q=https://play.google.com/store/apps/details?id%3Dcom.gangfort.game.android&sa=D&ust=1464126095844000&usg=AFQjCNFSTZ1p_uBvIHYw97c29XwJU3gEjw",
"price": "1.99",
"like": 0,
"show": "-SFCH5-Kvkc_nfQxnpZ8",
"provider": "-PFCH5-Kvkc_nfQxnpZ8",
"imageUrl": "https://www.google.com/url?q=https://lh3.googleusercontent.com/DV5mFhDQ2ADEbiF0S4cxL313JDqRazy9et7Etky5WtH7gxsm9DvbHhb52N0MH1swgfzR%3Dw300-rw&sa=D&ust=1464126095844000&usg=AFQjCNEymzxjrdN8wwL4qN40w5i8i9MlPw"
}
},
"shows": {
"-SFCH5-Kvkc_nfQxnpZ8": {
"number": 432,
"name": "Google I/O Secrets Revealed",
"date": "05/22/2016",
"app": ["-AFCH5-Kvkc_nfQxnpZ8", "-AFCH5-Kvkc_nfQxnpZ9"],
"url": "http://podnutz.com/aaa432/"
}
},
"providers": {
"-PFCH5-Kvkc_nfQxnpZ8": {
"firstName": "Steve",
"lastName": "McLaughlin",
"nick": "D2d",
"app": ["-AFCH5-Kvkc_nfQxnpZ8", "-AFCH5-Kvkc_nfQxnpZ9"]
}
}
}
这是应用模型 从' ember-data / model'中导入模型; 从' ember-data / attr'导入attr; 从' ember-data / relationships';
导入{belongsTo}export default Model.extend({
name: attr('string'),
playLink: attr('string'),
price: attr('string'),
like: attr('number'),
show: belongsTo('show', {
async: true
}),
provider: belongsTo('provider', {
async: true
}),
imageUrl: attr('string')
});
这是show model
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { hasMany } from 'ember-data/relationships';
export default Model.extend({
number: attr('number'),
name: attr('string'),
date: attr('date'),
apps: hasMany('app'),
url: attr('string')
});
这是我的路线
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('app');
}
});
这是ember控制台的样子
所以问题是当我尝试访问模板中的show对象时,它不会出现
{{#each model as |show|}}
{{app.show.name}}
{{/each}}
更新
从标记的外观来看,似乎有些东西在这里工作
当我登录app.show
时,这是控制台答案 0 :(得分:0)
您没有在模板中迭代每个应用模型。 它应该是那样的
{{#each model as |app|}}
{{app.show.name}}
{{/each}}
你的每个循环都是{{#each model as |show|}}
答案 1 :(得分:0)
试试这个:
MyDbContext
我建议利用ember-promise helpers,因为app和show之间的关系是异步的:
{{#each model as |app|}}
{{#if app.show}}
{{app.show.name}}
{{/if}}
{{else}}
Loading apps...
{{/each}}
答案 2 :(得分:0)
您的apps: hasMany('app')
模型中的show
引用似乎会覆盖您在展示模型中定义的关系。