鍍金池/ 問(wèn)答/HTML/ 加載json中的新聞標(biāo)題列表后如何限制只顯示10條

加載json中的新聞標(biāo)題列表后如何限制只顯示10條

加載json中的新聞標(biāo)題列表后如何限制只顯示10條? 因?yàn)閖son文件中有上百條新聞信息,該如何實(shí)現(xiàn)只讓其顯示10條?

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .item {height:48px;line-height:48px;}
        .item::before {content:'.';padding-right:10px;};
    </style>
</head>

<body>
    <div id="result"></div>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script>
    $(document).ready(function() {
        $.ajax({
            type: "GET",
            url: "list.json",
            dataType: "json",
            success: function(data) {
                $.each(data, function(i, item) {
                    var hahaid = item.id
                    var content ='<div class="item">';
                        content +='<a href=3.html?id=' + hahaid + '>' + item.title + '</a>';
                        content +='</div>';
                    $("#result").append(content);
                })
            }
        })
    });
    </script>


</body>
</html>
回答
編輯回答
獨(dú)白

一次獲取后將數(shù)據(jù)緩存,然后根據(jù)需求,是做分頁(yè),還是滾動(dòng)加載。

2017年6月24日 21:54
編輯回答
萌面人
$.each(data.slice(0,10),```````
2018年2月24日 23:00
編輯回答
浪蕩不羈
if(i<10){
    // 顯示
}
2017年8月13日 19:23
編輯回答
放開(kāi)她
let showData = data.slice(0,10)
2018年7月3日 09:15