简体   繁体   English

如何从角度2的json中获取部分数据

[英]how to fetch partial data from a json in angular 2

let us have a JSON file of having 1000 records like below 让我们有一个具有1000条记录的JSON文件,如下所示

[{
    "name": "aaa",
    "age": 20
}, {
    "name": "bbb",
    "age": 21
}, ......]

Is there any way to get partial data from json like first 100 objects or any, if i clicked load more button, then i can have another 100 objects from json, preferably in angular 2 or any popular javascript libraries?? 有没有办法从json中获取部分数据,例如前100个对象或任何对象,如果我单击“加载更多”按钮,那么我可以从json中获得另外100个对象,最好是在angular 2或任何流行的javascript库中? Need to load Partial data from JSON instead of getting all data and taking some part of data Thanks in advance 需要从JSON加载部分数据,而不是获取所有数据并获取部分数据,谢谢

You can use slice function but you should be sure that you have an array of json objects. 您可以使用slice函数,但应确保您具有json对象数组。

let startIndex = 0;
let endIndex = 100;

let toBeShowed = yourArray.slice(startIndex ,endIndex);

in the next click of your load more button you will increase " startIndex , endIndex " with 100 or whatever you want to increase with. 在您的“加载更多”按钮的下一次单击中,您将“ startIndexendIndex ”增加100或要增加的任何值。

As I can see this cant be done by just angular from FE side. 如我所见,仅从FE侧倾斜就不能做到这一点。 you need to support it from BE side. 您需要从BE方面提供支持。 like to send some range of data to BE and it will return this range of results. 希望将一定范围的数据发送到BE,它将返回此范围的结果。 similar to pagination on tables. 类似于桌上的分页。

firebase example : Firebase示例

citiesRef.where("population", ">", 100000).orderBy("population").limit(2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM