Ver código fonte

DIYTable组件的rows被多次stringify,暂时使用多次parse的方式防止报错

xujunjie 1 ano atrás
pai
commit
ea163b71c0
1 arquivos alterados com 20 adições e 2 exclusões
  1. 20 2
      src/components/DDComponents/DIYTable/index.tsx

+ 20 - 2
src/components/DDComponents/DIYTable/index.tsx

@@ -212,7 +212,16 @@ function DIYTable(props: IProps) {
       for (let index = 0; index < rows.length; index++) {
         // 把每一行的数据提出来到一个对象里
         if (rows) {
-          const row = typeof rows[index] === 'string' ? JSON.parse(rows[index]) : rows[index];
+          let row = [];
+          row = rows[index];
+          // row被stringify了多次,需要多次parse
+          while (typeof row === 'string') {
+            try {
+              row = JSON.parse(row);
+            } catch (error) {
+              row = [];
+            }
+          }
 
           if (index === 0) {
             // 列配置
@@ -251,7 +260,16 @@ function DIYTable(props: IProps) {
       if (displayOnly) {
         for (let index = 0; index < rows.length; index++) {
           // 把每一行的数据提出来到一个对象里
-          const row = typeof rows[index] === 'string' ? JSON.parse(rows[index]) : rows[index];
+          let row = [];
+          row = rows[index];
+          // row被stringify了多次,需要多次parse
+          while (typeof row === 'string') {
+            try {
+              row = JSON.parse(row);
+            } catch (error) {
+              row = [];
+            }
+          }
           const rowData: any = {};
 
           if (!row) break;