0
以下代碼預計在FooterButtons集合中插入3對文檔,然後這些值在頁腳模板中的3個按鈕上顯示爲標籤。顯示模板中集合的項目
但是,當「click.menuItem」被調用時,它只在集合中插入「YES」。任何想法爲什麼它是經紀人和最好的解決辦法?由於
服務器和客戶端代碼
FooterButtons = new Mongo.Collection('footerButtons');
Server代碼
Meteor.publish('footerButtons', function(){
return FooterButtons.find();
});
客戶端代碼
Meteor.subscribe('footerButtons');
//---main_menu.js--------------------
Template.mainMenu.events({
'click .menuItem': function (event) {
FooterButtons.insert({button:"NO", button:"EXTRA", button:"YES"});
}
});
//---footer.html---------------
<template name="footer">
{{#each footerButtons}}
<h1>
<button class="col-xs-4" type="button">{{button}}</button>
</h1>
{{/each}}
</template>
//---footer.js---------------
Template.footer.helpers({
footerButtons: function(){
return FooterButtons.find();
}
});