Limit with filter - instafeed.js

天大地大妈咪最大 提交于 2019-12-13 00:42:48

问题


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

回答1:


You are correct, the filter is always applied after the limit option.

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

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



来源:https://stackoverflow.com/questions/26701197/limit-with-filter-instafeed-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!