我有时会发现自己向多个模板声明相同的数据。例如:
Template.auction_page.auctionDurations = function () {
return [ 30, 60, 120 ];
};
Template.auction_editor.auctionDurations = function () {
return [ 30, 60, 120 ];
};
我可以通过使用全局使其变得更好:
Template.auction_page.auctionDurations = function () {
return global.auctionDurations;
};
Template.auction_editor.auctionDurations = function () {
return global.auctionDurations;
};
但是有没有办法完全摆脱声明?换句话说,有没有办法默认将一些全局数据共享给多个模板?