主要是因为对象的互相引用,怎么样才能造成对象的互相引用呢?

var a = {};
var b = {};
a.b = b;
b.a = a;

怎么解决,反正我试了很多,最后选择深度clone

 this.planAddParams['actionInfoList'] = this.deepClone(this.actionInfoList)
  deepClone (source) {
      if (!source || typeof source !== 'object') {
        throw new Error('error arguments', 'shallowClone')
      }
      var targetObj = this.testArray(source) ? [] : {}
      for (var keys in source) {
        if (source.hasOwnProperty(keys)) {
          if (source[keys] && typeof source[keys] === 'object') {
            targetObj[keys] = source[keys].constructor === Array ? [] : {}
            targetObj[keys] = this.deepClone(source[keys])
          } else {
            targetObj[keys] = source[keys]
          }
        }
      }
      return targetObj
    },
    testArray(obj) {
      return Object.prototype.toString.call(obj) === '[object Array]'
    }

主要是后台要求的数据结构比较坑
Javascript报错Converting circular structure to JSON

相关文章:

  • 2021-07-09
  • 2022-01-13
  • 2021-05-04
  • 2021-11-06
  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
  • 2021-11-01
猜你喜欢
  • 2022-12-23
  • 2021-09-24
  • 2022-01-12
  • 2022-12-23
  • 2022-12-23
  • 2021-10-28
  • 2022-12-23
相关资源
相似解决方案