0
一個分組集合多數民衆贊成在不工作的代碼:ORDERBY在linq.js
var grouping = Enumerable.from(periods)
.select(function(p){return new PeriodViewModel(p)})
.groupBy("$.periodNumber")
.orderBy("$.date")
.toArray();
的periodviewmodels被periodNumber分組和日期應由日期進行排序上升,但是這不會發生,我猜猜它是因爲orderBy中的選擇器應該以某種方式引用分組結果...
我不知道。這是測試數據,所以你可以嘗試自己:
{
"periods": [
{
"id": 1,
"content": "this is not a test",
"date": 1,
"periodNumber": 1,
"documents": [
{
"name": "Homework.doc"
},
{
"name": "Todo.xls"
}
]
},
{
"id": 3,
"content": "this might be a test",
"date": 2,
"periodNumber": 1,
"documents": [
{
"name": "Homework.doc"
},
{
"name": "Todo.xls"
}
]
},
{
"id": 5,
"content": "This is a clause",
"date": 3,
"periodNumber": 1,
"documents": [
{
"name": "Homework.doc"
},
{
"name": "Todo.xls"
}
]
},
{
"id": 1,
"content": "and not sth to share for all",
"date": 5,
"periodNumber": 2,
"documents": [
{
"name": "Homework.doc"
},
{
"name": "Todo.xls"
}
]
},
{
"id": 2,
"content": "hello kitty???",
"date": 2,
"periodNumber": 3,
"documents": [
{
"name": "Homework.doc"
},
{
"name": "Todo.xls"
}
]
},
{
"id": 1,
"content": "Flynnie winnie",
"date": 1,
"periodNumber": 3,
"documents": [
{
"name": "Homework.doc"
},
{
"name": "Todo.xls"
}
]
},
{
"id": 1,
"content": "what do yo say about chol and ra?",
"date": 1,
"periodNumber": 4,
"documents": [
{
"name": "Homework.doc"
},
{
"name": "Todo.xls"
}
]
}
]
}
哈哈,我也想過,但後來我認爲訂單不是由該組保存......也許...應該嘗試過! – Elisabeth 2014-09-22 14:51:02
我不知道這是否在任何規範中,但是我使用的所有linq實現在分組時保留順序。可能是因爲保持這個訂單更容易。項目在處理時被拋入一個組中,通常作爲一個列表/數組。使用不保存順序的集合是沒有意義的。 – 2014-09-22 15:28:27
原來指定:[Enumerable.GroupBy()](http://msdn.microsoft.com/en-us/library/vstudio/bb534501%28v=vs.100%29.aspx#remarksToggle)。 「IGrouping」對象是根據產生每個「IGrouping 」的第一個鍵的源元素的順序產生的。分組中的元素按順序產生他們出現在源頭上。「換句話說,組中的組和項目在從源集合處理時是有序的。 –
2014-09-23 05:16:19