1

我正在使用伟大的工具instafeed.js与 instagram 的 api 进行交互。我目前正在尝试将结果过滤为仅image.type === 'video'. 我已经能够让它发挥作用。唯一的问题是它永远不能满足limit:10集合。不知何故,它可能会拉出所有类型(imagevideo),然后应用过滤器。10仅对视频应用过滤器时是否可以满足限制?

var feed = new Instafeed({
  limit: '10',
  sortBy: 'most-liked',
  resolution: 'standard_resolution',
  clientId: 'xxxxx', 
  template:'<div class="tile"><div class="text"><b>{{likes}} &hearts; </b>{{model.user.full_name}}</div><img class="item" src="{{image}}"></div>',
  filter: function(image) {
    return image.type === 'video';
  }
});
4

1 回答 1

1

你是对的,filter总是在选项之后应用。limit

要解决这个问题,请尝试将 设置limit为更高的数字,然后在事后删除额外的图像:

var feed = new Instafeed({
  limit: 30,
  sortBy: 'most-liked',
  resolution: 'standard_resolution',
  clientId: 'xxxxx', 
  template:'<div class="tile"><div class="text"><b>{{likes}} &hearts; </b>{{model.user.full_name}}</div><img class="item" src="{{image}}"></div>',
  filter: function(image) {
    return image.type === 'video';
  },
  after: function () {
    var images = $("#instafeed").find('div');
    if (images.length > 10) {
      $(images.slice(10, images.length)).remove();
    }
  }
});

您还可以在 Github 上查看此线程以获取更多详细信息。

于 2014-11-03T19:45:00.287 回答