使用过滤器限制-instafeed.js [英] Limit with filter - instafeed.js

查看:106
本文介绍了使用过滤器限制-instafeed.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using the great tool of instafeed.js to interact with instagram’s api. I am currently trying to filter results to only be image.type === 'video'. I have been able to get that to work. The only problem is that it never satisfies the limit:10 set. Somehow it may be pulling all types(image and video) and then applying the filter. Is it possible to meet the limit 10 while applying a filter for videos only?

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

推荐答案

您是正确的,在选项之后,总是在之后应用filter.

要解决此问题,请尝试将limit设置为更高的数字,然后在出现以下情况后删除其他图像:

To get around that, try setting the limit to a higher number, then removing extra images after the fact:

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上查看此线程 ,以获取更多详细信息.

You can also check this thread on Github for more details.

这篇关于使用过滤器限制-instafeed.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆