为instafeed生成的每个列表项生成id

时间:2016-03-16 08:46:52

标签: javascript jquery instafeedjs

我正在使用instafeed.js来获取最新的Instagram帖子,我需要为每个列表项生成id。我怎么能这样做?

JS:

var feed = new Instafeed({
    clientId: '<id>', //enter client id here
    limit: 5,
    sortBy: 'most-liked',
    //<div class="likes">&hearts; {{likes}}</div> ************************* likes count
    template: '<li><a href="{{link}}" target="_blank"><img class="img-responsive img-circle center-block" src="{{image}}"></li>'
});
feed.run();

HTML:

<ul id="instafeed"></ul>

2 个答案:

答案 0 :(得分:0)

取自gist

var ID = function () {
  return '_' + Math.random().toString(36).substr(2, 9);
};

然后只需调用该函数。

答案 1 :(得分:0)

您可以使用{{id}}关键字

var feed = new Instafeed({
  clientId: '<id>', //enter client id here
  limit: 5,
  sortBy: 'most-liked',
  template: '<li id="{{id}}"><a href="{{link}}" target="_blank"><img class="img-responsive img-circle center-block" src="{{image}}"></li>'
});
feed.run();
<script src="https://cdn.imnjb.me/libs/instafeed.js/1.3.2/instafeed.js"></script>
<ul id="instafeed"></ul>