我正在开发一个非常基本的 ember 应用程序,但我似乎无法让它显示 belongsto 模型。
我的用户模型:
News.User = DS.Model.extend({
username: DS.attr('string'),
items: DS.hasMany('News.Item')
});
News.User.FIXTURES = [
{
"id": 1,
"username": "Bobba_Fett",
"items": [1,2]
}]
我的商品型号:
'use strict';
News.Item = DS.Model.extend({
title: DS.attr('string'),
url: DS.attr('string'),
domain: DS.attr('string'),
points: DS.attr('number'),
comments: DS.hasMany('News.Comment'),
user: DS.belongsTo('News.User')
});
News.Item.FIXTURES = [
{
"id": 1,
"title": "This is story 1",
"url": "http://google.com",
"domain": "google.com",
"points": 45,
"comments": [1,2,3],
"user_id": 1
},
{
"id": 2,
"title": "This is another story",
"url": "http://yahoo.com",
"domain": "yahoo.com",
"points": 30,
"comments": [1,2,3],
"user_id": 1
}
]
我的 html (问题是用户名没有显示,它只是空白),其他一切都显示正常:
<script type="text/x-handlebars" data-template-name="items">
<div class="row">
<ul>
{{#each itemList}}
<a href="upvote">▲</a><a {{bindAttr href="url"}}>{{title}}</a> ({{domain}})<br />
<small>{{points}} Ups -- submitted by {{user.username}}</small><br />
{{/each}}
</ul>
</script>