当用户名在 javascript 中匹配时删除 post

Deleting post when username matches in javascript

我正在制作一个网站,您可以在其中使用 Meteor post 图片和消息。我一直在尝试添加一个事件,当当前登录用户和 post 的 poster 相同时,您可以删除 posts。这是我想到的,但它不起作用。它一直说这不是我的 post,即使这两个匹配。我认为 this.currentUser 有问题,但我不确定如何解决 i.

Template.posts.events({
'click .delete-task': function (event) {
    if (this.username === this.currentUser) {
        Collections.Appwall.remove({
        _id: this._id
        });
    } else {
        Materialize.toast('This is not your post', 4000);
        return false;
    }
}});

您的代码片段没有提供太多信息,但如果您使用的是当前登录用户的用户名,并且您使用的是标准流星帐户包,那么您可以尝试使用

if (this.username === Meteor.user().username)

我的假设是 username 是您的数据实体的一个属性,而不是 currentUser