2014-11-02 110 views
1

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

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

@StevenSchobert请在这里提供另一个帮助。 – 2014-11-02 15:52:46

回答

1

你是正确的,filterlimit选项后始终应用

要解决这个问题,尝试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(); 
    } 
    } 
}); 

您还可以检查this thread在Github上的更多细节。

+0

收益率仍低于10。 – 2014-11-04 02:03:20

+0

您最近30个帖子中的视频少于10个吗?您也可以尝试将限制设置为-1。 – 2014-11-04 02:21:09

+0

它用'limit:-1'发射错误。你可以查看这个[JSFIDDLE](http://jsfiddle.net/bullseye2346/gkavx7md/) – 2014-11-04 02:33:37