Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
96 views
in Technique[技术] by (71.8m points)

javascript - Display number of pages

I want to create paginations but I have a little problem. I want to display number of pages. So I have this code:

//How much I have pages I have
const pages = Math.ceil(totalItems / perSite);

OK. I count pages but I need to display that. I tryed do that in for look. It look like this

    //...
    //How much I have pages I have
    const pages = Math.ceil(totalItems / perSite);
    const Pagination = pages => {
        let list = []
        for(let i = 1; i<=pages; i++){
            list.push(<li key={i}>{i}</li>)
        }
        return list;
    }
    return (
            <div className="row">
                <ul>
                    <Pagination pages={pages} />
                </ul>
            </div>
    );

Of course its the part of code which concerns my problem. I don't have an error but my paginations doesn't display. How can I display number of pages?

@Edit I found the problem but I don't know how I can solve that. My data comes from server and I save that in my local store. Total items use length os my local store so if app is rendering length=0. If I run other page and nex time then I will go to this page it works correctly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...