我正在尝试返回所有赞助类型的列表,然后是可能属于该赞助类型的任何合作伙伴。我正在使用夹具适配器,这是我的数组:
var partnersArray = [
{ id: 1, sponsorship:[1], sponsorName: 'NYT', url: 'http://nyt.com/', image: 'images/sponsors/nyt.png'},
{ id: 1, sponsorship:[2], sponsorName: 'WSJ', url: 'http://wsj.com/', image: 'images/sponsors/wsj.png'},
{ id: 1, sponsorship:[2], sponsorName: 'CNN', url: 'http://cnn.com/', image: 'images/sponsors/cnn.png'},
];
var sponsorshipArray = [
{ id: 1, sponsorshipName:'Big Dog', sponsorshipPrice:'$25,000'},
{ id: 2, sponsorshipName:'Dog', sponsorshipPrice:'$10,000'},
{ id: 3, sponsorshipName:'Canine', sponsorshipPrice:'$5,000'},
{ id: 4, sponsorshipName:'Pup', sponsorshipPrice:'$2,000'},
{ id: 5, sponsorshipName:'Puppy', sponsorshipPrice:'$1,000'},
];
这些是我的模型:
App.Sponsorship = DS.Model.extend({
sponsorshipName: DS.attr('string'),
sponsorshipPrice: DS.attr('string'),
partners: DS.hasMany('App.Partner')
});
App.Sponsorship.FIXTURES = sponsorshipArray;
App.Partner = DS.Model.extend({
sponsorship: DS.attr('string'),
sponsorName: DS.attr('string'),
image: DS.attr('string'),
url: DS.attr('string'),
partnerSponsor: DS.belongsTo('App.Sponsorship'),
});
App.Partner.FIXTURES = partnersArray;
这是我的路线:
App.PartnersRoute = Ember.Route.extend({
model: function() {
return App.Sponsorship.find();
},
setupController: function(controller, model) {
controller.set('model', model);
}
});
这是我的车把
<script type="text/x-handlebars" id="partners">
<h2>Partners</h2>
{{#each sponsorship in controller}}
{{sponsorship.sponsorshipName}}<br />
{{sponsorship.partners}}<br /><br />
{{/each}}
</script>
这是我的输出:
Big Dog
<DS.ManyArray:ember345>
Dog
<DS.ManyArray:ember346>
Canine
<DS.ManyArray:ember347>
Pup
<DS.ManyArray:ember348>
Puppy
<DS.ManyArray:ember349>
我似乎无法弄清楚我在这里缺少什么并对其进行了一些简化,以便我可以看到我应该在哪里添加代码......有什么建议吗?