Steem.js Example #3. Get Posts more than 20 posts, pagination.

in steem •  7 years ago  (edited)

WordPress Post : http://junn.in/archives/575

Github source :

  1. https://github.com/junn279/steemjs_example/blob/master/steem03_1.php (lite version)
  2. https://github.com/junn279/steemjs_example/blob/master/steem03.php

Continue to our previous example, this time I’ll introduce get_discussions_… functions.

I don’t know why, but functions are named like as below.

지난 포스팅에 이어, get_discussion 함수를 이용해 20개 이상의 자료, 연속되는 자료 받기를 확인해볼 예정이다. 함수 이름을 왜 discussion이라고 했는지 잘 모르겠다.

At this time, make a source like this. A Little bit different from previous sources, but this is more effective to view sequential 10, 20 (next 10) posts. I used getDiscussionsByCreated. Literally, byCreated means ‘retrieve posts in the order when they were created.

Look at ‘query’ and number of ‘limit’ is 11 not 10. Last one is for ‘retrieve next 10 posts’

기본 틀을 위과 같이 잡는다. 일단 불러오는 갯수를 11로 한 것은, 마지막 데이터는 다음 10개를 불러어오기 위한 데이터로 필요하기 때문이다.

As member variation of ‘query’ object, set start_author and start_permlink from last 11th post(but array index starts from number zero, so number 10 indicate the 11th post).

And then if you watch the developer console, you can see the retrieved posts.

But in this case, you should not put ‘inner query2~steem.api.getDis.. function’ out of first getDiscussionBy… function. Because steem.api is running synchronously.

I’m sure there is another way to run these sequential functions asynchronously. But I don’t know yet.

받아온 데이터의 마지막(11번째; array에서 index는 10) 포스트의 자료를 이용해서 다음 내용을 불러온다. 함수 내부에 다시 함수를 넣어야하는 이유는 동기화로 진행되는 함수이기 때문에 밖으로 뺄 경우 제대로된 변수값이 세팅되지 않기 때문이다.

Finally, I made a source using this function, put a button and by using it, we can get next 10 posts.

마지막으로 만든 소스는 버튼을 이용해서 계속적으로 포스트를 연장하는 소스이다.

https://github.com/junn279/steemjs_example/blob/master/steem03.php

There is a ‘click’ button, and then you can get next 10 posts. These are match to what we can see through https://steemit.com/created/kr perfectly. (Be sure to be different from my result)

아래와 같은 결과를 만들어내었다.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Upvoted and RESTEEMED!

Thank you~ but I think you resteem unmeaningly.

감사합니다 !! 도움 많이 되었습니다