【发布时间】:2015-07-09 00:44:36
【问题描述】:
我想在 angulajs 中将以下对象数组附加到现有的对象数组中,以实现加载更多功能。
即,每次都将 AJAX 响应附加到现有的响应中。
我有一个变量,$scope.actions,其中包含以下 JSON 数据,
{
"total": 13,
"per_page": 2,
"current_page": 1,
"last_page": 7,
"next_page_url": "http://invoice.local/activities/?page=2",
"prev_page_url": null,
"from": 1,
"to": 2,
"data": [
{
"id": 2108,
"action_type_id": 202,
"user_id": 1
},
{
"id": 2108,
"action_type_id": 202,
"user_id": 1
}
]
}
我想在每次此变量时附加以下JSON 响应。
{
"data": [
{
"id": 2108,
"action_type_id": 202,
"user_id": 1
},
{
"id": 2108,
"action_type_id": 202,
"user_id": 1
}
]
}
我试过$scope.actions.data.concat(data.data);
但它不工作并收到以下错误消息
$scope.actions.data.concat is not a function
【问题讨论】:
-
Angular 同时拥有复制对象的
extend和copy -
由于新变量与第一个示例中的
data属性完全相同,因此进行一些说明会有所帮助
标签: javascript jquery angularjs merge append