瀏覽代碼

排序优化

shaogen1995 8 月之前
父節點
當前提交
9ce8ada3db
共有 1 個文件被更改,包括 7 次插入5 次删除
  1. 7 5
      src/pages/A1home/Bottom/index.tsx

+ 7 - 5
src/pages/A1home/Bottom/index.tsx

@@ -46,20 +46,22 @@ function Bottom({ setTopObj, pageKey }: Props) {
 
     const myList1Temp = data.catalogRoot
 
+    // console.log('ppppppppppp', data.scenes)
+
     const myObjTemp: any = {}
     data.scenes.forEach((v: any) => {
       myList1Temp.forEach((c: any) => {
         if (c.children[0] === v.category) {
-          if (myObjTemp[c.children[0]]) myObjTemp[c.children[0]].push(v)
-          else myObjTemp[c.children[0]] = [v]
+          if (myObjTemp[c.children[0]]) {
+            myObjTemp[c.children[0]].push(v)
+          } else myObjTemp[c.children[0]] = [v]
         }
       })
     })
 
+    // 手动排序
     for (const key in myObjTemp) {
-      myObjTemp[key] = myObjTemp[key].sort(
-        (a: any, b: any) => Number(a.sceneTitle.split('-')[1]) - Number(b.sceneTitle.split('-')[1])
-      )
+      myObjTemp[key] = myObjTemp[key].sort((a: any, b: any) => a.weight - b.weight)
     }
 
     setMyList1([...KKlist1Temp, ...myList1Temp])