我從服務器獲得前十個對象並將其存儲在$ scope.data中。它看起來像這樣:如何將新結果添加到現有變量?
$scope.check = function(search, count) {
request.getData(search, count).success(function(response) {
$scope.data = response;
});
};
當用戶向下滾動,我想未來十年對象HTML代碼添加到$ scope.data並重復這些20個對象與NG-重複。後來30,40,等等。
<ul scroll>
<li ng-repeat="element in data">
{{element.id}}
{{element.name}}
{{element.surname}}
</li>
</ul>
這是我的PHP:
while ($data = mysqli_fetch_array($result)) {
$array[] = array("id"=>(int) $data['ID'], "name"=>$data['FirstName'], "surname"=>$data['LastName'], "mobile"=>$data['MobilePhone']);
}
echo json_encode($array);
,並返回是這樣的:
[{"id":885,"name":"Jeremy","surname":"Goodrow","mobile":"+48-792-518-774"},{"id":886,"name":"Noella","surname":"Modestino","mobile":"+48-792-518-774"},{"id":887,"name":"Lief","surname":"Regoli","mobile":"+48-792-518-774"}]
所以,我的問題是:我怎麼能將新的十個結果添加到現有變量($ scope.data)?當我第一次加入它,我這樣做,它的偉大工程:
$scope.data = response;
但我必須如何添加新十個結果這個變量?服務器的響應每次都是相同的。我不能做這樣的事情,因爲它一點兒也不工作:
$scope.data += response;
我也不能推響應$ scope.data,因爲NG-重複顯示它是這樣的:
Resulst不分開。請幫幫我。也許,我必須將元素推送到$ scope.data,但是我必須在ng-repeat中更改哪些內容?我不知道。
like'$ scope.data = $ scope.data.concat(response);' – Grundy