问题
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}} ♥ </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}} ♥ </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