Tumblr 点赞按钮在 ajax 加载后不起作用

Tumblr like button not working after ajax load

我在我的 tumblr 主题中使用 pjaxmasonry。我只是想出了如何在单击 pjax'd link 后让砌体工作,但现在的问题是点赞按钮不再起作用。到目前为止,这是我的代码:

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);
});

我相信你需要使用 pjax:success。这应该给你 data 对象。

$(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);

});

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