$scope.testArr = [
{id:"1",name:"yi"},
{id:"2",name:"er"},
{id:"3",name:"san"},
{id:"4",name:"si"}
]
<div class="list">
<div ng-repeat="item in testArr" ng-click="foward(item)">{{item.name}}</div>
</div>问题:根据首次点击选中的项 重新生成数组 当前选中的项为数组的第一个元素,依次类推例如首次点击的是id为2的项 则新数组为:[{id:"2",name:"er"},{id:"3",name:"san"}, {id:"4",name:"si"}, {id:"1",name:"yi"}]首次选中的是id为3的项 新数组为[{id:"3",name:"san"}, {id:"4",name:"si"},{id:"1",name:"yi"}{id:"2",name:"er"}]
1 回答
温温酱
TA贡献1752条经验 获得超4个赞
function reSort(arr,index){ index = index || 0; if( !arr || arr.length === 0 || index > arr.length ) return arr; var front = arr.slice(0,index); var end = arr.slice(index); return end.concat(front); }var arr = [ {id:"1",name:"yi"}, {id:"2",name:"er"}, {id:"3",name:"san"}, {id:"4",name:"si"} ]; reSort(arr,1);
添加回答
举报
0/150
提交
取消