Javascript 如何通过链接参数显示指定数量的数据?

Javascript 如何通过链接参数显示指定数量的数据?,javascript,json,json-server,Javascript,Json,Json Server,我想从json服务器显示100个对象中的示例5。有没有像这样的参数?哪种类型 const url = "http://localhost:8000/players?_sort=points&_order=desc"; const url = "http://localhost:8000/players?_sort=points&_order=desc"; let template = ""; fe

我想从json服务器显示100个对象中的示例5。有没有像这样的参数?哪种类型

const url = "http://localhost:8000/players?_sort=points&_order=desc";



const url = "http://localhost:8000/players?_sort=points&_order=desc";
    let template = "";

    fetch(url)
        .then((res) => res.json())
        .then((data) => {
            data.forEach((player, idx) => {
                template += `
            <div class='modal-leaderboard__player-name'>
            <h2>${idx + 1}.&nbsp;</h2>
            <h2 data-player-rank>${player.name}&nbsp;</h2>
            <h2 style='margin-left: auto'>&nbsp;&nbsp;<span data-points-rank>${player.points}</span>&nbsp;points</h2>
            </div>
        `;
            });

            this.rank.innerHTML += template;
        });
consturl=”http://localhost:8000/players?_sort=points&_order=desc";
常量url=”http://localhost:8000/players?_sort=points&_order=desc";
让模板=”;
获取(url)
.然后((res)=>res.json())
。然后((数据)=>{
data.forEach((播放器,idx)=>{
模板+=`
${idx+1}。
${player.name}
${player.points}点
`;
});
this.rank.innerHTML+=模板;
});

如果您指的是前5项,可以在var idx上添加一个条件:

...
 if(parseInt(idx)<6){
     template+=...
     ....
     this.rank.innerHTML += template;
  }
...

。。。

if(parseInt(idx)如果您是指前5项,可以在var idx上添加一个条件:

...
 if(parseInt(idx)<6){
     template+=...
     ....
     this.rank.innerHTML += template;
  }
...

。。。

if(parseInt(idx)需要更多详细信息。哪个代码正在运行后端?它是众所周知的cms吗?等等。我只想显示5个结果不是所有的数据库。我没有办法知道你的后端服务器代码。所以这必须在你的后端代码上解决。现在有办法解决你的问题,只需在你的url中添加一个键。如果你共享关于你的后端系统的一些信息,那么可能是someone可以建议一个解决方案。但我所有的后端都是来自json服务器的数据需要更多详细信息。哪个代码正在运行后端?它是众所周知的cms吗?等等。我只想显示5个结果不是所有的数据库。我无法了解您的后端服务器代码。所以这必须在您的后端代码上解决。现在有办法解决您的问题,只需向您的服务器添加一个密钥若你们分享了一些关于你们的后端系统的信息,那个么也许有人可以建议一个解决方案。但我的所有后端都是来自json服务器的数据