无限滚动ajax召回后,Tumblr之类的按钮不起作用

问题描述:

有一些类似的帖子,但它们已经过时了,据我所知,Tumblr 不久前更新了 API 的类似部分.

There are a few similar posts but they are quite out of date and Tumblr has updated the like part of the API not too long ago as far as I'm aware.

创建一个赞按钮就像{点赞按钮}

Creating a like button is as simple as {LikeButton}

这很好用,但是在 ajax 回想从下一页获取更多帖子后,like 按钮不再起作用.

and this works great, but after the ajax recalls to get more posts from what would be the next page, the like button no longer works.

我查看了文档,它指出我需要实现以下其中一项,我想知道是否有人可以为我指明正确的方向?我一直试图让它工作几个小时.

I have had a look at the documentation and it states that I need to implement one of the following, I was wondering if anyone could point me in the right direction? I've been trying to get this to work for hours.

如果这有助于回答,我编写了一个示例博客,javascript 可以执行大量新图像的实现.

I made up an example blog if this helps contribute to answering, the javascript can do the mass amount of the implementing of new images.

http://stackoverflowexample.tumblr.com/

如果您需要更多信息,我很乐意编辑并添加所需内容,谢谢!

If you need anymore info, i'll happily edit this and add what's required, thank you!

概述

改编自我之前的回答:使用 Tumblr Like Button无限滚动

Tumblr 声明我们需要调用两个函数之一来获取赞状态.我建议如下:

Tumblr states we need to call one of two functions to get the Like Status. I would suggest the following:

函数:Tumblr.LikeButton.get_status_by_post_ids([n,n,n])描述:请求单个帖子的赞状态.获取一组帖子 ID

Function: Tumblr.LikeButton.get_status_by_post_ids([n,n,n]) Description: Request Like status for individual posts. Takes an array of post IDs

一旦 ajax 请求成功,我们应该有一个 data 对象(包含新帖子等).

Once the ajax request is successful , we should have a data object (containing new posts, etc).

我们需要创建一个 postIDs 数组,该数组包含 data 对象中每个帖子的 ID/编号.添加帖子 ID 的最简单方法是使用主题变量 {PostID}.

We need to create an array of postIDs, which is an array containing an ID / number for each post in the data object. Easiest way to add the the post id is to use the theme variable {PostID}.

<article class="post" id="{PostID}">...</article>

jQuery 帖子 ID 数组

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

Tumblr.LikeButton

Tumblr.LikeButton.get_status_by_post_ids($newPostIDs);

提示

创建数组并在 ajax 请求成功后调用 Tumblr.LikeButton 并在您为新帖子运行其他函数的地方调用.这也可以使用纯 javascript 来完成:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

Hints

Create the array and call Tumblr.LikeButton once the ajax request is successful and in a place where you run other functions for the new Posts. This can also be done with pure javascript as using: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map