contrastData.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //比较对象的值
  2. export function contrastObj(newval, oldval) {
  3. var reg = /^[A-Za-z]+$/;
  4. for (let newitem in newval) {
  5. for (let olditem in oldval) {
  6. if (!reg.test(newitem)) {
  7. delete newval.newitem
  8. }
  9. if (!reg.test(oldval)) {
  10. delete oldval.olditem
  11. }
  12. if (newitem == olditem) {
  13. if (newval[newitem] != oldval[olditem]) {
  14. return true
  15. }
  16. }
  17. }
  18. }
  19. return false
  20. }
  21. //比较数组的值
  22. export function contrastList(newlist, oldlist) {
  23. if (newlist.length != oldlist.length) {
  24. return true
  25. }
  26. let reg = /^[A-Za-z]+$/;
  27. for (var i = 0; i < newlist.length; i++) {
  28. for (let newitem in newlist[i]) {
  29. for (let olditem in oldlist[i]) {
  30. if (!reg.test(newitem)) {
  31. delete newlist[i].newitem
  32. }
  33. if (!reg.test(oldlist[i])) {
  34. delete oldlist[i].olditem
  35. }
  36. if (newitem == olditem) {
  37. if (newlist[i][newitem] != oldlist[i][olditem]) {
  38. return true
  39. }
  40. }
  41. }
  42. }
  43. }
  44. return false;
  45. }