简体   繁体   中英

how to fetch partial data from a json in angular 2

let us have a JSON file of having 1000 records like below

[{
    "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?? Need to load Partial data from JSON instead of getting all data and taking some part of data Thanks in advance

You can use slice function but you should be sure that you have an array of json objects.

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.

As I can see this cant be done by just angular from FE side. you need to support it from BE side. like to send some range of data to BE and it will return this range of results. similar to pagination on tables.

firebase example :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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