2

我正在使用 instafeed js 从 instagram 调用照片。有没有办法将每 4 个图像包装在一个 div 中?这甚至可能吗?这是我的代码:

  jQuery(window).load(function(){

      var userFeed = new Instafeed({
        get: 'user',
        userId: 1509441625,
        accessToken: '1509441625.5b9e1e6.c20b3eb91b15404ab30084283ab3a9c9',
        limit : 4,             
        resolution:'standard_resolution',
        template: '<a target="_Blank" href="{{link}}"><img src="{{image}}" /></a> ',

      });
      userFeed.run();

    });

我联系了 instafeed 的开发人员,他给了我一段未经测试的代码,我正在尝试调试:

      var count = 0;
      var userFeed = new Instafeed({
        get: 'user',
        userId: 1509441625,
        accessToken: '1509441625.5b9e1e6.c20b3eb91b15404ab30084283ab3a9c9',
        limit : 4,             
        resolution:'standard_resolution',
        filter: function(image) {
            count += 1;
            if (count % 4 === 0) {
                image.customTagOpen = '<div>';
                image.customTagClose = '</div>';
            } else {
                image.customTagOpen = '';
                image.customTagClose = '';
            }
            return true;
        },
        template: '{{model.customTagOpen}}<a target="_Blank" href="{{link}}"><img src="{{image}} /></a>{{model.customTagClose}}';

      });
      userFeed.run();

    });

但我收到一个错误:在列出属性后缺少“}”。有什么建议吗?

4

3 回答 3

3

template在选项行的末尾有一个错误放置的分号。

尝试将该分号更改;为逗号,

template: '{{model.customTagOpen}}<a target="_Blank" href="{{link}}"><img src="{{image}} /></a>{{model.customTagClose}}',
于 2014-12-19T05:37:28.087 回答
1

除了史蒂文的答案,您还可以使用此修复程序:

您可以使用此修复程序:

if (count % 4 === 0 || count === 0) {
    image.customTagOpen = '<div>';
    image.customTagClose = '';
} else if (count + 1 % 4 === 0) {
    image.customTagOpen = '';
    image.customTagClose = '</div>';
} else {
    image.customTagOpen = '';
    image.customTagClose = '';
}

干杯,

于 2015-09-30T12:37:05.637 回答
0

对于每 4 个计数的 div 行,请使用以下命令:

  filter: function(image) {
    count += 1;
    if (count == 1 || (count - 1) % 4 == 0 ) {
      image.customTagOpen = '<div class="row">';
      image.customTagClose = '';
    } else if (count % 4 == 0) {
      image.customTagOpen = '';
      image.customTagClose = '</div>';
    } else {
      image.customTagOpen = '';
      image.customTagClose = '';
    }
    return true;
  },

或使用

  filter: function(image) {
    if (count == 0 || count % 4 == 0 ) {
      image.customTagOpen = '<div class="row">';
      image.customTagClose = '';
    } else if ((count + 1) % 4 == 0) {
      image.customTagOpen = '';
      image.customTagClose = '</div>';
    } else {
      image.customTagOpen = '';
      image.customTagClose = '';
    }
    count += 1;
    return true;
  },
于 2019-02-16T05:43:07.043 回答