我試圖重新排序如下今天的日期數組的數組:訂購基於當前日期
[
{
"index": "0",
"day": "Monday",
"food": "Salad"
},
{
"index": "1",
"day": "Friday",
"food": "Pasta"
},
{
"index": "2",
"day": "Sunday",
"food": "Pasta"
},
{
"index": "3",
"day": "Thursday",
"food": "Pasta"
},
{
"index": "4",
"day": "Tuesday",
"food": "Pasta"
},
{
"index": "2",
"day": "Sunday",
"food": "Pasta"
},
{
"index": "5",
"day": "Wednesday",
"food": "Pasta"
},
{
"index": "6",
"day": "Saturday",
"food": "Pasta"
}
]
今天要說的是Saturday
,訂貨後,由項目指數的預期成果是:6,2 2,0,4,5,3,1 如果今天是Tuesday
,由索引輸出是:4,5,3,1,6,2,2,0
我使用moment.js
,等遠遠沒有爲此創建一個非龐大的代碼。 最後,我想將代碼包裝在自定義orderBy過濾器中以用於ng-repeat指令。
爲什麼'Sunday'出現兩次? –
@miparnisari只是爲了說明可以在數組中複製對象。 – user1027620
你能告訴我們你到目前爲止使用了什麼代碼嗎? – anurupr