Bladeren bron

修复table新数据无法刷新的问题(重写新旧数据isEquals方法)

zhuth 8 jaren geleden
bovenliggende
commit
1a58342cfe

+ 7 - 2
kanban-client/app/component/Table.dev.jsx

@@ -164,12 +164,14 @@ class TableModel extends React.Component {
 		}
 
 		this.dataArr = result;
+		console.log(this.dataArr);
 		this.dataIndex = 0;
 	}
 
 	setRefresh() {
 		this.changeData();
 		if (this.dataArr.length > 1) {
+			console.log('setRefresh');
 			this.timing({
 				intervalFunction: function () {
 					this.changeData();
@@ -194,6 +196,7 @@ class TableModel extends React.Component {
 	clearInterval() {
 		for (let index in this.timerKeys) {
 			clearInterval(this.timerKeys[index]);
+			console.log('移除' + this.timerKeys[index]);
 			this.timerKeys.splice(index, 1);
 		}
 	}
@@ -210,11 +213,13 @@ class TableModel extends React.Component {
 		this.clearInterval();
 	}
 	componentWillReceiveProps(nextProps) {
-		if (isEqual(this.sortData(nextProps.data), this.newProps.data)) {
-			this.newProps = nextProps;
+		if (isEqual(nextProps.data, this.newProps.data)) {
 			return;
 		}
+		this.newProps = nextProps;
 		this.clearInterval();
+		this.initSort();
+		this.sortData(this.newProps.data);
 		this.splitData();
 		this.setRefresh();
 	}

+ 4 - 2
kanban-client/app/component/Table.jsx

@@ -210,11 +210,13 @@ class TableModel extends React.Component {
 		this.clearInterval();
 	}
 	componentWillReceiveProps(nextProps) {
-		if (isEqual(this.sortData(nextProps.data), this.newProps.data)) {
-			this.newProps = nextProps;
+		if (isEqual(nextProps.data, this.newProps.data)) {
 			return;
 		}
+		this.newProps = nextProps;
 		this.clearInterval();
+		this.initSort();
+		this.sortData(this.newProps.data);
 		this.splitData();
 		this.setRefresh();
 	}

+ 1 - 0
kanban-client/app/component/converter.dev.js

@@ -1,4 +1,5 @@
 function converter(data) {
+    console.log(data);
     let { content } = data;
     let { title, items } = content;
     let itemsarr = items ? (items instanceof Array ? items : [items]) : [];

+ 13 - 2
kanban-client/app/component/factory.dev.js

@@ -5,13 +5,13 @@ import MessageBox from '../src/MsgBox/MessageBox.jsx';
 import { converter } from './converter.dev.js';
 import URL from '../constants/url.dev.json';
 
-import tempdata from '../data/testform.json';
+import tempdata from '../data/testTableRefresh.json';
 
 class Factory extends React.Component {
 
     constructor(props) {
         super(props);
-        this.dev = 'local ';
+        this.dev = 'local';
         this.index = 0;
         this.state = {
             titleHeight: 0,
@@ -119,6 +119,17 @@ class Factory extends React.Component {
             this.setState({
                 model: converter(tempdata.data[0]),
             });
+            this.refreshNext = setInterval(function () {
+                if (this.index >= tempdata.data.length-1) {
+                    this.index = 0;
+                } else {
+                    this.index++;
+                }
+                this.setState({
+                    model: converter(tempdata.data[this.index]),
+                });
+            }.bind(this), 10000)
+
         }else {
             this.getModelConfig(code[0]);
         }

+ 11 - 3
kanban-client/app/utils/BaseUtils.js

@@ -84,10 +84,18 @@ function isEqual(a,b){
     }
     //如果是数组类型
     if(classNameA == '[object Array]'){
-        if(a.toString() == b.toString()){
-            return true;
+        let i = 0;
+        for(i; i < a.length;) {
+            if(isEqual(a[i], b[i])) {
+                i++;
+            }else {
+                break;
+            }
         }
-        return false;
+        if(i==a.length) {
+            return true;
+        }else 
+            return false;
     }
 }