【发布时间】:2019-07-08 06:22:40
【问题描述】:
我有一个 json 数组,我将它分配给一个 $scope 对象以在前端显示。我想根据给定的 id 重新排列这个数组。 这就是我的初始数组的样子。
$scope.listData = [{
id: 1,
name: adam,
title: testing title,
description: testing description
},
{
id: 2,
name: zampa,
title: testing title,
description: testing description
},
{
id: 3,
name: Aaron,
title: testing title,
description: testing description
}]
对于重排,例如如果给定的id是3,记录的重排应该是3,1,2。
我尝试过使用 angular.forEach 循环,但没有成功。
【问题讨论】:
-
所以您只想将具有给定 ID 的项目移动到数组的开头?
-
正确。只是重新排列,不删除不删除。