gpt4 book ai didi

javascript - 如何定位特定类别以将 View 切换到用户?

转载 作者:行者123 更新时间:2023-11-28 05:13:11 25 4
gpt4 key购买 nike

当用户单击“我的评论”按钮时,我想向他们显示该帖子的评论。截至目前,在页面加载时,这些注释被类隐藏。

我不知道如何隐藏评论,然后当用户单击特定评论按钮时,仅显示帖子的这些评论。

现在我显示每个帖子的所有评论。

我有一个 post._id,我可以用它来定位一组特定的评论,但我不确定如何使用该数据。有什么想法吗?

Jade 文件

.fullPostContainer
each post in posts
.media.white.paddingBoxForPost
.media-left.media-middle
a.removeTextDeco(href=post.link, target='_blank')
img.media-object(src=post.img, alt='facebook logo')

.media-body
a.removeTextDeco(href=post.link, target='_blank')
div#mainTitlePost.media-heading.postTitleFont= post.title
div#mainShortDesc.descriptionFont= post.description
//form.formSub
// label(for='upvote')
button.upvoteClick.btn.btn-lg.btnColor(value= post._id)
span.glyphicon.glyphicon-fire= post.upvote
button.btn.commentsInit.btn-lg.btnColor(value= post._id)
span.glyphicon.glyphicon-comment
.commentsForTheWin.hideOnLoad
p this is some text
span

JS文件

$(function () {

$('.commentsInit').click(function () {


// grabs value of button which is post._id
// var uniCommID = $(this).attr("value");


$('.hideOnLoad').toggle("slow");


$.ajax({
type: "GET",
url: "/api/comments"
}).success(function (users) {

var a = JSON.stringify(users);
$('.commentsForTheWin span').text("Comments but not really for " + a);

})

})

});

我现在从我的数据库中得到了我想要的东西,但我只是很难弄清楚如何定位特定的类(或者如果这是可能的)。

最佳答案

我使用 jQuery .closest().commentsInit 按钮向上遍历树,存储对父 .paddingBoxForPost 的引用放在一个变量中,并使用它来定位相关元素。

$(function() {
$('.commentsInit').click(function() {

// grabs value of button which is post._id
// var uniCommID = $(this).attr("value");

var $post = $(this).closest('.paddingBoxForPost');

$post.find('.hideOnLoad').toggle("slow");

$.ajax({
type: "GET",
url: "/api/comments"
}).success(function(users) {
var a = JSON.stringify(users);
$post.find('.commentsForTheWin span').text("Comments but not really for " + a);
})
})
});

关于javascript - 如何定位特定类别以将 View 切换到用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41205253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com