我无法渲染模型的“hasMany”部分。我似乎和这个人有类似的问题,但我仍然不知道该怎么办。
这是相关的JS:
App.Router.map(function() {
this.resource('account', function() {
this.resource('transaction', {
path: '/transaction/:transaction_id'
});
});
});
App.AccountIndexRoute = Ember.Route.extend({
model: function() {
return App.Account.find();
}
});
App.TransactionRoute = Ember.Route.extend({
model: function() {
return App.Transaction.find();
}
});
App.Store = DS.Store.extend({
revision: 12,
adapter: 'DS.FixtureAdapter'
});
App.Account = DS.Model.extend({
title: DS.attr('string'),
transactions: DS.hasMany('App.Transaction')
});
App.Account.FIXTURES = [
{
id: 1,
title: 'Your account',
transactions: [1, 2, 3]
}];
App.Transaction = DS.Model.extend({
date: DS.attr('date'),
name: DS.attr('string'),
amount: DS.attr('number'),
paidWith: DS.attr('string'),
account: DS.belongsTo('App.Account')
});
App.Transaction.FIXTURES = [
{
id: 1,
date: new Date(2012, 04, 17),
name: 'Item 1',
amount: 10,
paidWith: 'credit card',
account_id: 1
},
{
id: 2,
date: new Date(2012, 04, 01),
name: 'Item 2',
amount: 50,
paidWith: 'cash',
account_id: 1
},
{
id: 3,
date: new Date(2012, 03, 28),
name: 'Item 3',
amount: 100,
paidWith: 'bank transfer',
account_id: 1
}
];
和模板:
<script type="text/x-handlebars" id="account/index">
<h2>Transactions</h2>
<table>
<thead>
<tr>
<th>Date</th>
<th>Item</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
{{#each model}}
{{#each transaction in transactions}}
<tr>
<td>{{date transaction.date}}</td>
<td>{{#linkTo 'transaction' this}}{{transaction.name}}{{/linkTo}}</td>
<td>£{{transaction.amount}}</td>
</tr>
{{/each}}
{{/each}}
</tbody>
</table>
</script>
有人可以提供帮助吗?