[英]Generic session variable key template helper with Meteor
How can I make the following helper more generic so that I can set arbitrary session vars with matching template vars and retrieve them without such a repetitive pattern? 如何使以下助手更通用,以便我可以设置具有匹配模板变量的任意会话变量并在没有这种重复模式的情况下检索它们?
Template.feedback5.helpers({
'posX': function() {
return Session.get('posX');
},
'dragPosition': function() {
return Session.get('dragPosition');
},
'stuck': function() {
return Session.get('stuck');
},
'dragging': function() {
return Session.get('dragging');
}
});
You can register a global helper to get any Session variable given its key : 您可以注册一个全局帮助程序,以获取任何给定其键的Session变量:
Template.registerHelper("getSession",function(key){
return Session.get(key);
});
And use it like this in your Spacebars templates : 并在您的Spacebars模板中使用它:
{{getSession "posX"}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.