Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果所有者meteor js,则在模板中显示元素_Javascript_Mongodb_Meteor - Fatal编程技术网

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();
  }
});