在ajax加载后Tumblr像按钮不工作

时间:2022-06-22 23:00:31

I am using pjax and masonry in my tumblr theme. I just figured out how to get masonry to work after clicking a pjax'd link, but now the problem is that the like button is not working anymore. Here is my code so far:

我在tumblr主题中使用pjax和masonry。我刚刚弄清楚如何在点击pjax'd链接后让砌体工作,但现在的问题是,like按钮不再起作用了。到目前为止,这是我的代码:

html:

<article class="entry" id="{PostID}">

</article>

jquery:

$(document).ajaxComplete(function(){
   $('#content').imagesLoaded(function(){
      $('#content').masonry('reloadItems').masonry();
   });

   var $newPosts   = $(data).find('.entry');
   var $newPostIDs = $newPosts.map(function () {
     return this.id;
   }).get();

   Tumblr.LikeButton.get_status_by_post_ids($newPostIDs);
});

1 个解决方案

#1


I believe you need to use pjax:success. This should give you the data object.

我相信你需要使用pjax:成功。这应该给你数据对象。

$(document).on('pjax:success', function( event, data, status, xhr, options ) {

 $('#content').imagesLoaded(function(){
    $('#content').masonry('reloadItems').masonry();
 });

 var $newPosts   = $(data).find('.entry');
 var $newPostIDs = $newPosts.map(function () {
   return this.id;
 }).get();

 Tumblr.LikeButton.get_status_by_post_ids($newPostIDs);

});

Source: https://github.com/defunkt/jquery-pjax#events

#1


I believe you need to use pjax:success. This should give you the data object.

我相信你需要使用pjax:成功。这应该给你数据对象。

$(document).on('pjax:success', function( event, data, status, xhr, options ) {

 $('#content').imagesLoaded(function(){
    $('#content').masonry('reloadItems').masonry();
 });

 var $newPosts   = $(data).find('.entry');
 var $newPostIDs = $newPosts.map(function () {
   return this.id;
 }).get();

 Tumblr.LikeButton.get_status_by_post_ids($newPostIDs);

});

Source: https://github.com/defunkt/jquery-pjax#events