这似乎应该很简单。假设我有以下模型:
App.Folder = DS.Model.extend({
folder_id: DS.attr('number'),
folder_name: DS.attr('string'),
items: DS.hasMany('App.Item')
});
App.Item = DS.Model.extend({
item_id: DS.attr('number'),
folder_id: DS.attr('number'),
item_name: DS.attr('string'),
folder: DS.belongsTo('App.Folder')
});
...以及以下数据:
App.Folder.FIXTURES = [
{
id: 1,
folder_name: 'My First Folder',
items: [100]
},
{
id: 2,
folder_name: 'Another Folder',
items: [101]
},
{
id: 3,
folder_name: 'Folder 3',
items: [102]
}
];
App.Item.FIXTURES = [
{
id: 100,
folder_id: 1,
item_name: 'This is an item'
},
{
id: 101,
folder_id: 2,
item_name: 'A cleverly named item'
},
{
id: 102,
folder_id: 3,
item_name: 'This one is also an item in a folder'
}
];
现在,在我的“项目”模板中,我是否应该能够做这样的事情来显示与项目相关的文件夹:
<script type="text/x-handlebars" data-template-name="snapshot">
<div class="row-fluid property-row-alt">
<div class="span4 property-label">item name:</div>
<div class="span8">{{ item_name }}</div>
</div>
<div class="row-fluid property-row">
<div class="span4 property-label">folder:</div>
<div class="span8">{{ folder.folder_name }}</div>
</div>
</script>
“ folder.folder_name ”是我试图在这里确定的关键语法。也许这是不可能的,但我希望得到相关的文件夹并在我的项目模板中深入了解它的文件夹名称。我可以在 Ember 中执行此操作吗?使用最新版本。