3
我想返回所有的贊助類型之後,可能是根據該贊助類型的任何合作伙伴的名單。我現在用的夾具適配器,這裏是我的數組:灰燼數據 - 撕心裂肺一對多模板
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>
我似乎無法找出我在做什麼在這裏失蹤,有所簡化,以便我能看到我應該添加代碼...什麼建議嗎?
這雖然聽起來很合乎邏輯並沒有爲我工作。我收到錯誤「Can not read property'FIXTURES'of undefined」我正在使用車把並且正在輸出: {{#each贊助在控制器中}} {{sponsorship.sponsorshipName}} {{sponsorship.partners}} { {/每}} 我應該使用不同的方法? – wfaye
該錯誤看起來像'FIXTURES'沒有定義。檢查分配前的陣列是否存在。 –
的事情是,如果我放棄{{sponsorship.partners}},然後我的燈具的工作就好了... ...它看來我錯誤地瞄準了這個相關數據。我試圖搜索如何做到這一點,但找不到任何文件。 – wfaye