Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.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 Json延迟加载图像_Javascript_Jquery_Json_Lazy Loading - Fatal编程技术网

Javascript Json延迟加载图像

Javascript Json延迟加载图像,javascript,jquery,json,lazy-loading,Javascript,Jquery,Json,Lazy Loading,我有这个Json文件 http://localhost/mediamonks-15-years-gritt-glamour-website/deploy/htdocs/api/folder/Leuke%20Mensen/images 这就是我从API获取图像的方式 $.ajax('http://localhost/mediamonks-15-years-gritt-glamour-website/deploy/htdocs/api/folder/Leuke%20Mensen/images').

我有这个Json文件

http://localhost/mediamonks-15-years-gritt-glamour-website/deploy/htdocs/api/folder/Leuke%20Mensen/images
这就是我从API获取图像的方式

$.ajax('http://localhost/mediamonks-15-years-gritt-glamour-website/deploy/htdocs/api/folder/Leuke%20Mensen/images').then(response =>
    {
        var temp = [];
        for(var i = 0; i<response.length; i++){
            temp.push('http://d1ftcqzt8gr3o4.cloudfront.net/'+response.data[i].thumb);
        }
        this.thumbnails(temp);

        var images = response.data.map((data:IImageData) =>
        {
            return {
                big: 'http://d1ftcqzt8gr3o4.cloudfront.net/'+ data.big,
                thumb: 'http://d1ftcqzt8gr3o4.cloudfront.net/'+ data.thumb
            }
        });
        this.images(images);
    });
$.ajax('http://localhost/mediamonks-15-years-gritt-glamour-website/deploy/htdocs/api/folder/Leuke%20Mensen/images)。然后(响应=>
{
var-temp=[];
对于(var i=0;i
{
返回{
大:'http://d1ftcqzt8gr3o4.cloudfront.net/“+data.big,
拇指:'http://d1ftcqzt8gr3o4.cloudfront.net/'+data.thumb
}
});
这个.图像(图像),;
});

所以我的问题是:只有10张图片的最佳方式是什么。我可以用代码来完成吗?还是最好更改api,使其每10个图像包装到另一个对象中?

分页最常用的解决方案是使用
startIndex
count
。您必须更改服务并添加startIndex和count get参数。之后,您必须在查询的末尾添加(我假设您使用mysql)
limit
并传递
startIndex
count
变量


limit函数是这样工作的:
limit 3,7
表示您希望获取从4到10的行。

您可以更改api以接收图像索引和偏移量(表示要检索的图像数量),例如:
http://localhost/mediamonks-15-years-gritt-glamour-website/deploy/htdocs/api/folder/Leuke%20Mensen/images/5/150
将从第5个图像开始为您提供150个图像。为什么不使用
$.getJSON()