Ember.js 余烬:如何以Handlebar语法显示相关数据(余烬数据)?
看 我有以下形式的数据:Ember.js 余烬:如何以Handlebar语法显示相关数据(余烬数据)?,ember.js,ember-data,Ember.js,Ember Data,看 我有以下形式的数据: publication: { id: '1', title: 'first title', bodytext: 'first body', author: { id: '100', name: 'Jan' } }, 我想在哈佛商学院部分显示作者姓名。在hbs出版物(显示每个出版物)中,我使用以下语法,但这不起作用: {{publicat
publication: {
id: '1',
title: 'first title',
bodytext: 'first body',
author: {
id: '100',
name: 'Jan'
}
},
我想在哈佛商学院部分显示作者姓名。在hbs出版物(显示每个出版物)中,我使用以下语法,但这不起作用:
{{publication.author.name}}
{{author.name}}
在publications/edit hbs(在publications中选择后编辑一份出版物)中,我使用以下语法,但这不起作用:
{{publication.author.name}}
{{author.name}}
我应该如何访问嵌入式数据?首先,您的工作小提琴,很抱歉,我将其移植到jsbin,因为我更喜欢它,但这不会以任何方式影响功能: 现在我所做的更改,基本上我所做的是定义一个
应用程序。Author
有许多出版物,一个应用程序。Publication
属于一个应用程序。Author
并完成了相应的装置:
App.Author = DS.Model.extend({
name: DS.attr('string'),
publications: DS.hasMany('App.Publication'),
didLoad: function () {
console.log('Author model loaded', this);
}
});
App.Publication = DS.Model.extend({
title: DS.attr('string'),
bodytext: DS.attr('string'),
author: DS.belongsTo('App.Author'),
didLoad: function () {
console.log('Publication model loaded', this);
}
});
//FIXTURES DATA
App.Publication.FIXTURES = [
{
id: '1',
title: 'first title',
bodytext: 'first body',
author: 100
},
{
id: '2',
title: 'second title',
bodytext: 'second post',
author: 300
}
];
App.Author.FIXTURES = [
{
id: '300',
name: 'Marc',
publications: [2]
},
{
id: '100',
name: 'Jan',
publications: [1]
}
];
希望对您有所帮助。首先,您的工作小提琴,很抱歉我将其移植到了jsbin,因为我更喜欢它,但这不会以任何方式影响功能: 现在我所做的更改,基本上我所做的是定义一个
应用程序。Author
有许多出版物,一个应用程序。Publication
属于一个应用程序。Author
并完成了相应的装置:
App.Author = DS.Model.extend({
name: DS.attr('string'),
publications: DS.hasMany('App.Publication'),
didLoad: function () {
console.log('Author model loaded', this);
}
});
App.Publication = DS.Model.extend({
title: DS.attr('string'),
bodytext: DS.attr('string'),
author: DS.belongsTo('App.Author'),
didLoad: function () {
console.log('Publication model loaded', this);
}
});
//FIXTURES DATA
App.Publication.FIXTURES = [
{
id: '1',
title: 'first title',
bodytext: 'first body',
author: 100
},
{
id: '2',
title: 'second title',
bodytext: 'second post',
author: 300
}
];
App.Author.FIXTURES = [
{
id: '300',
name: 'Marc',
publications: [2]
},
{
id: '100',
name: 'Jan',
publications: [1]
}
];
希望能有所帮助。一如既往的好答案!我应该雇佣你。。。我想我也可以在出版物数据中使用“嵌入式”作者。将在此基础上进一步工作,因为我希望在编辑部分中有一个包含所有作者和正确作者的选择列表(双向绑定)。@cyclomarc,谢谢:),
{embedded:true}
可以,在您的用例中唯一的一件事是,FixtureAdapter
只是更详细的RESTAdapter
的子集,嵌入式记录应该在那里工作。一如既往的好答案!我应该雇佣你。。。我想我也可以在出版物数据中使用“嵌入式”作者。将在此基础上进一步工作,因为我希望在编辑部分中有一个包含所有作者和正确作者的选择列表(双向绑定)。@cyclomarc,谢谢:),{embedded:true}
可以,在您的用例中唯一的一件事是,FixtureAdapter
只是更详细的RESTAdapter
的子集,嵌入式记录应该在那里工作。