问题描述
我有一个快速应用程序,您可以在其中创建和查看帖子。我正在尝试使其制作成这样,如果他们发布了,则在用户帖子旁边会显示一个编辑图标。我尝试使用车把帮手进行此操作。
editIcon: function (user,loggedUser,floating = true) {
console.log(user,loggedUser);
if (user._id.toString() == loggedUser._id.toString()) {
if (floating) {
return `<div>edit icon</div>`;
}
} else {
return '';
}
},
基本上,用户是user._id。 loggingUser是帖子中的ID,它与用户ID相同。
这是我的车把的样子:
{{#each posts}}
<div class="post-extra">
<div class="card-image">
<!-- User is the logged in user and then post id (_id) -->
{{{editIcon user _id}}}
</div>
<a href="#" class="user-link">{{user.username}}</a>
<h2>{{postTitle}}</h2>
</div>
{{else}}
<p>No posts to display</p>
{{/each}}
</div>
问题在于,当我控制台登录用户和日志用户时,返回的ID是不同的。不过在我的mongodb中,帖子中的用户ID和用户ID相同。
我的帖子和用户对象:
帖子:
_id:ObjectId("5f8523d8b58f4919908e3895") <-- this is being returned..
postTitle:"Test post"
postBody:"<div>stuff</div>"
user:ObjectId("5f8522c9c0ec222ea4b7c8c0") <-- instead of this
createdAt:2020-10-13T03:49:44.333+00:00
__v:0
用户:
_id: ObjectId("5f8522c9c0ec222ea4b7c8c0"),// User id
username: 'test',email: '[email protected]',password: 'hashed password here',createdAt: 2020-10-13T03:45:13.018Z,__v: 0
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)