[英]How can I target a specific class to toggle views to user?
當用戶單擊“我的評論”按鈕時,我想向他們顯示該帖子的評論。 到目前為止,在頁面加載時,這些注釋已被一個類隱藏。
我無法弄清楚如何隱藏顯示的評論,然后在用戶單擊特定評論按鈕時僅顯示帖子的那些評論。
現在,我顯示每個帖子的所有評論。
我有一個post._id,可以用來定位一組特定的注釋,但是我不確定如何使用該數據。 有什么想法嗎?
玉銼
.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);
})
})
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.