Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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 检查Blaze中的平等性?_Javascript_Meteor_Meteor Blaze_Meteor Accounts - Fatal编程技术网

Javascript 检查Blaze中的平等性?

Javascript 检查Blaze中的平等性?,javascript,meteor,meteor-blaze,meteor-accounts,Javascript,Meteor,Meteor Blaze,Meteor Accounts,用户只能删除发布帖子的人。但是,用户可以看到所有帖子。javascript代码为: var postedBy = Meteor.user(); var currentPost = this._id; Posts.insert({ name:postName, createdAt:new Date(), postId:currentPost, postedBy:postedBy }); HTML代码是: <template name="posts"> {{#if currentUse

用户只能删除发布帖子的人。但是,用户可以看到所有帖子。javascript代码为:

var postedBy = Meteor.user();
var currentPost = this._id;
Posts.insert({
name:postName,
createdAt:new Date(),
postId:currentPost,
postedBy:postedBy
});
HTML代码是:

<template name="posts">
{{#if currentUser}}
{{> addPost}}
<ul>
    {{#each post}}
        <li>{{> postItem}}</li>

    {{/each}}
</ul>
{{/if}}
</template>


<template name="postItem">
    <li>
    <h4>{{name}}</h4>
    <i>Posted by {{postedBy.username}} on {{createdAt}}</i>

     [<a href="#" class="delete-post">Delete</a>] 

    </li>
</template>
<template name='addPost'>
<input type='text' placeholder='Add post here' name='postName' id ='myinput'>
<button class="btn btn" type="button" id='btn'>Post</button>
</template>

{{{#如果当前用户}}
{{>addPost}
    {{#每个帖子}
  • {{>positem}
  • {{/每个}}
{{/if}
  • {{name}} 由{{postedBy.username}发布在{{createdAt}} []
  • 邮递
    currentUser.username和postedBy.username分别显示登录用户和发布特定帖子的用户的姓名

    我正在尝试使用删除锚标记

    {{#if currentUser.username==postedBy.username}} 
    [<a href="#" class="delete-post">Delete</a>]
    {{/if}}
    
    {{#如果currentUser.username==postedBy.username}
    []
    {{/if}
    
    但它在命令提示符中显示错误。我知道这是错误的,但我想不出任何其他方法。如何编写此“if”语句来检查当前用户是否是发布此帖子的用户?
    请帮助我,因为我是Meteor的新手。很抱歉英语不好。

    你不能在空格键中使用任意JavaScript表达式。添加如下所示的帮助器:

    Template.postItem.helpers({
      canDelete: function (){
        return Meteor.user().username === this.postedBy.username;
      }
    });
    
    {{#if canDelete}}
      <a href="#" class="delete-post">Delete</a>
    {{/if}}
    
    然后您可以在模板中使用它,如下所示:

    Template.postItem.helpers({
      canDelete: function (){
        return Meteor.user().username === this.postedBy.username;
      }
    });
    
    {{#if canDelete}}
      <a href="#" class="delete-post">Delete</a>
    {{/if}}
    
    {{#if canDelete}
    {{/if}
    

    另外请注意,建议的方法不是将用户对象复制到每篇文章中,而是将用户id存储在
    postedBy

    中。您不能在空格键中使用任意JavaScript表达式。添加如下所示的帮助器:

    Template.postItem.helpers({
      canDelete: function (){
        return Meteor.user().username === this.postedBy.username;
      }
    });
    
    {{#if canDelete}}
      <a href="#" class="delete-post">Delete</a>
    {{/if}}
    
    然后您可以在模板中使用它,如下所示:

    Template.postItem.helpers({
      canDelete: function (){
        return Meteor.user().username === this.postedBy.username;
      }
    });
    
    {{#if canDelete}}
      <a href="#" class="delete-post">Delete</a>
    {{/if}}
    
    {{#if canDelete}
    {{/if}
    
    另外请注意,建议的方法不是将用户对象复制到每篇文章中,而是将用户id存储在
    postedBy