Javascript 如果所有者meteor js,则在模板中显示元素
我正在编写一个消息应用程序,它为用户提供了删除/编辑提交的给定消息的功能。我想写的是这样的:Javascript 如果所有者meteor js,则在模板中显示元素,javascript,mongodb,meteor,Javascript,Mongodb,Meteor,我正在编写一个消息应用程序,它为用户提供了删除/编辑提交的给定消息的功能。我想写的是这样的: {{#if currentUser._id === this._id}} <!-- Show --> {{/if}} 但此时我陷入了困境假设您的消息文档有一个用户ID字段,您只需执行以下操作: Template.message.helpers({ isOwner: function() { return this.userId === Meteor.userId();
{{#if currentUser._id === this._id}}
<!-- Show -->
{{/if}}
但此时我陷入了困境假设您的消息文档有一个
用户ID
字段,您只需执行以下操作:
Template.message.helpers({
isOwner: function() {
return this.userId === Meteor.userId();
}
});
以及:
{{{#如果是所有者}
{{/if}
您还可以为此制作一个更灵活、可重用的全局帮助器:
Template.registerHelper('isCurrentUser',函数(userId){
返回userId==Meteor.userId();
});
{{{#如果是当前用户所有者ID}{{/if}}
当然,您还需要使用或使用自定义方法验证服务器上的更新。假设您的消息文档有一个
userId
字段,您只需执行以下操作:
Template.message.helpers({
isOwner: function() {
return this.userId === Meteor.userId();
}
});
以及:
{{{#如果是所有者}
{{/if}
您还可以为此制作一个更灵活、可重用的全局帮助器:
Template.registerHelper('isCurrentUser',函数(userId){
返回userId==Meteor.userId();
});
{{{#如果是当前用户所有者ID}{{/if}}
当然,您还需要使用或使用自定义方法验证服务器上的更新。谢谢您的回答,非常简单!谢谢你的回答,很简单!
Template.message.helpers({
isOwner: function() {
return this.userId === Meteor.userId();
}
});