Javascript Json延迟加载图像
我有这个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').
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()
?