我有以下数组:
var data = [
{street: "Галенка", house: "11", flats: "10,11,12,13,17,18,21,24,27,29,3,30,32,33,36,4,40", isNotApply: false},
{street: "Галенка", house: "3", flats: "1,12,14,15,16,19,2,21,23,24,28,29,3,30,31,32,6", isNotApply: true},
{street: "Літке", house: "110", flats: "0", isNotApply: true},
{street: "Вадима Гурова", house: "11", flats: "10,100,101,102,104,105", isNotApply: false},
{street: "Вадима Гурова", house: "120", flats: "0", isNotApply: true}
];
我使用 GroupBy 得到了这个结果,这很好,但是如何将IsNotApply设置为这 2 个数组的键?
var data = [
{street: "Галенка", house: "11", flats: "10,11,12,13,17,18,21,24,27,29,3,30,32,33,36,4,40,4…6,58,61,64,65,67,68,69,7,70,71,73,75,76,78,8,80,9", isNotApply: false},
{street: "Галенка", house: "3", flats: "1,12,14,15,16,19,2,21,23,24,28,29,3,30,31,32,6", isNotApply: true},
{street: "Літке", house: "110", flats: "0", isNotApply: true},
{street: "Вадима Гурова", house: "11", flats: "10,100,101,102,104,105,106,107,109,110,111,112,113…73,75,76,79,8,81,82,83,85,86,88,90,91,94,95,96,99", isNotApply: false},
{street: "Вадима Гурова", house: "120", flats: "0", isNotApply: true}
];
result = Enumerable.From(data)
.GroupBy(
"{IsNotApply: $.isNotApply, House: $.house}",
"{Street: $.street, House: $.house, Flats: $.flats}",
"{ data: $$.ToArray(), isNotApply: $.IsNotApply }",
"$.IsNotApply"
)
.ToArray();
console.log(result);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/linq.js/2.2.0.2/linq.js"></script>