0

I would like to know the suitable method to add pagination for my scenario: I using the "$('body').append(htmlText);" to display the items within the JSON object. How to add a pagination that display 1 item for each page depending on how many got in the JSON?

<!DOCTYPE html>
<html>

<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

</head>

<body>

<script>
    var data = [{
                 "name": "Bebe",
                 "lastname": "Rexha",
                 "description": "Young and beautiful",
                 "producer": "ABC Music",
                 "users_name": "BebeLove",
                },
                {
                  "name": "Katy",
                  "lastname": "Perry",
                  "description": "Cute and sweet",
                  "producer": "Kitty Music",
                  "users_name": "KittyCat",
                },
               ]

    var htmlText = '';

    for ( var key in data ) {
        htmlText += '<div class="div-conatiner">';
        htmlText += '<p class="p-name"> Name: ' + data[key].name + '</p>';
        htmlText += '<p class="p-loc"> LastName: ' + data[key].lastname + '</p>';
        htmlText += '<p class="p-desc"> Description: ' + data[key].description + '</p>';
        htmlText += '<p class="p-created"> Produced by: ' + data[key].producer + '</p>';
        htmlText += '<p class="p-uname"> Username: ' + data[key].users_name + '</p>';
        htmlText += '</div>';
    }

    $('body').append(htmlText);

</script>

</body>
</html>

Thank you. Cheer :)

1 Answer 1

1

The best way to do this would be to use Array.forEach()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.