如果数据来自服务器,如何使用无限滚动?

时间:2017-07-07 06:34:47

标签: angularjs

我想做无限滚动。我从服务器获取数据,并希望在时间显示25个元素。当用户向下滚动时,应显示接下来的25条记录。主要是它应该滚动内部滚动条。

httpHelper.get(urlName, false, function (err, response) {
    if (err) return err;
    getRecords(response.data.data, $scope.category);
});

var getRecords = function (data, category) {
    $scope.stocks.result = [];
    data.forEach(function (elem) {
        if (elem.duration === category) {
            $scope.stocks.result.push(elem);
        }
    });
};

Html:

<div class="row"
   ng-repeat="record in stocks.result | orderBy:stocks.symbol track by $index">

    <div class="col-md-2">
        {{record.Date|date:"dd-MMM"}}
    </div>
    <div class="col-md-2">
        {{record.symbol}}
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

向你的html添加无限滚动指令

SELECT * FROM ITEM I WHERE EXISTS 
(SELECT * FROM OPENJSON(I.CONTENT) WITH(id int) WHERE id IN (1, 2, 3, 9))

你的loadMore函数可以是这样的。

<div ng-repeat="record in stocks.result |orderBy:stocks.symbol track by $index" class="row" infinite-scroll="loadMore()">