我想知道,因为我还不能弄清楚,是否有办法附加流星的模板事件,例如:
Template.businessOperations.events({
'dblclick .display': function (evt, tmpl) {
//DO SOMETHING;
}
}
基于当前用户的角色。
例如:
if (Meteor.user().profile.type === 'admin') {
Template.businessOperations.events({
'dblclick .display': function (evt, tmpl) {
//DO SOMETHING;
}
}
}
我已经尝试过了,但是它不起作用,我也试图从实际的事件方法中获取用户,但是它也不起作用,我在这里没有找到正确的解决方案。
在此先感谢您的帮助。
仅当用户为管理员时才绑定事件是棘手的,因为在评估模板代码时,用户可能未登录。按照您的建议,在事件处理程序内部进行检查似乎是完全合理的。我会这样写:
Template.businessOperations.events({
'dblclick .display': function() {
if (Meteor.user() && (Meteor.user().profile.type === 'admin')) {
console.log('double click and admin!');
}
}
});
我添加了用于Meteor.user()
防止用户未登录的情况的额外检查。如果不可能的话,可以将其删除。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句