Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Instafeed js每4张图片添加一个包装器_Javascript_Jquery_Html_Plugins_Instafeedjs - Fatal编程技术网

Javascript Instafeed js每4张图片添加一个包装器

Javascript Instafeed js每4张图片添加一个包装器,javascript,jquery,html,plugins,instafeedjs,Javascript,Jquery,Html,Plugins,Instafeedjs,我正在使用instafeed js从instagram调用照片。有没有一种方法可以将每4个图像包装到一个div中?这可能吗?这是我的密码: jQuery(window).load(function(){ var userFeed = new Instafeed({ get: 'user', userId: 1509441625, accessToken: '1509441625.5b9e1e6.c20b3eb91b15404ab3

我正在使用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();

    });

但我得到一个错误:属性列表后缺少}。有什么建议吗?

模板选项行末尾的分号位置不正确

尝试更改分号;一个逗号


除了Steven的答案之外,您还可以使用此修复:

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 = '';
}
您可以使用此修复程序:

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

干杯,

对于div行,每4次计数使用以下内容:

  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;
  },

这消除了那个恼人的错误,谢谢!它仍然没有将每4个图像包装在一个div中: