На самом деле я ищу решение, где я могу отсортировать эти объекты
tempArr =[
{
BOQ_Txn_ID: 1456,
Chanage_At_KM: undefined,
Chanage_At_M: undefined,
Chanage_From_KM: "4",
Chanage_From_M: "023",
Chanage_To_KM: "2",
Chanage_To_M: "003",
Date: "1/Aug/2020",
Hight_Thikness: "1.000",
Item_Code: "HOT TACK COAT",
Loose_Qty_Per_Trip: undefined,
No_Of_Trip: undefined,
QNTY: "1980.000",
Side: "RHS",
Total_Length: "1.980",
Total_Loose_Qty: undefined,
Trip_Arr: [],
Trip_By: undefined,
Type_of_Work: "Road Works",
UNIT: "Sqm",
Width: "1.000",
calculation_type: "Addition" },
{
BOQ_Txn_ID: 1456,
Chanage_At_KM: undefined,
Chanage_At_M: undefined,
Chanage_From_KM: undefined,
Chanage_From_M: undefined,
Chanage_To_KM: "2",
Chanage_To_M: "003",
Date: "1/Aug/2020",
Hight_Thikness: "1.000",
Item_Code: "HOT TACK COAT",
Loose_Qty_Per_Trip: undefined,
No_Of_Trip: undefined,
QNTY: "1980.000",
Side: "LHS",
Total_Length: "1.980",
Total_Loose_Qty: undefined,
Trip_Arr: [],
Trip_By: undefined,
Type_of_Work: "Road Works",
UNIT: "Sqm",
Width: "1.000",
calculation_type: "Deduction"
},
{
BOQ_Txn_ID: 1456,
Chanage_At_KM: undefined,
Chanage_At_M: undefined,
Chanage_From_KM: undefined,
Chanage_From_M: undefined,
Chanage_To_KM: "2",
Chanage_To_M: "003",
Date: "1/Aug/2020",
Hight_Thikness: "1.000",
Item_Code: "HOT TACK COAT",
Loose_Qty_Per_Trip: undefined,
No_Of_Trip: undefined,
QNTY: "1980.000",
Side: "RHS",
Total_Length: "1.980",
Total_Loose_Qty: undefined,
Trip_Arr: [],
Trip_By: undefined,
Type_of_Work: "Road Works",
UNIT: "Sqm",
Width: "1.000",
calculation_type: "Deduction"
},
{
BOQ_Txn_ID: 1456,
Chanage_At_KM: undefined,
Chanage_At_M: undefined,
Chanage_From_KM: "0",
Chanage_From_M: "000",
Chanage_To_KM: "2",
Chanage_To_M: "003",
Date: "1/Aug/2020",
Hight_Thikness: "1.000",
Item_Code: "HOT TACK COAT",
Loose_Qty_Per_Trip: undefined,
No_Of_Trip: undefined,
QNTY: "1980.000",
Side: "RHS",
Total_Length: "1.980",
Total_Loose_Qty: undefined,
Trip_Arr: [],
Trip_By: undefined,
Type_of_Work: "Road Works",
UNIT: "Sqm",
Width: "1.000",
calculation_type: "Addition"},
{
BOQ_Txn_ID: 1456,
Chanage_At_KM: undefined,
Chanage_At_M: undefined,
Chanage_From_KM: "0",
Chanage_From_M: "023",
Chanage_To_KM: "2",
Chanage_To_M: "003",
Date: "1/Aug/2020",
Hight_Thikness: "1.000",
Item_Code: "HOT TACK COAT",
Loose_Qty_Per_Trip: undefined,
No_Of_Trip: undefined,
QNTY: "1980.000",
Side: "LHS",
Total_Length: "1.980",
Total_Loose_Qty: undefined,
Trip_Arr: [],
Trip_By: undefined,
Type_of_Work: "Road Works",
UNIT: "Sqm",
Width: "1.000",
calculation_type: "Addition"}
]
tempArr.sort(function (vote1, vote2) {
const from = vote1.Chanage_From_KM + ',' + vote1.Chanage_From_M;
const from2 = vote2.Chanage_From_KM + ',' + vote2.Chanage_From_M;
if ( vote1.calculation_type.length < vote2.calculation_type.length) {
if(vote1.side === vote2.side){
return -3;
}
}
if ( vote1.calculation_type.length > vote2.calculation_type.length){
if(vote1.side === vote2.side) {
return 1;
}
}
if ( from < from2) return -1;
});
Я хочу отсортировать этот массив по ->
- LHS -> Добавление -> От цепочки (от самой низкой к высокой)
- RHS -> Добавление -> От цепочки (от самой низкой к высокой)
- LHS -> Удержание
- RHS -> Удержание
Вкратце, я хочу проверить, является ли свойство Расчет_типа «сложением», а сторона свойства - «LHS». Тогда оно будет первым с цепочкой свойств_from_KM + Chainage_from_M в порядке возрастания. и если Сторона свойства - «RHS», она появится После всех LHS - Дополнительный список. Тогда Тип вычисления свойства - «Вычет». Будет идти с первой «LHS» до последней «RHS».
Пожалуйста, поделитесь своей идеей, если у вас есть Немного благодарности.