主要是因为对象的互相引用,怎么样才能造成对象的互相引用呢?
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]'
}
主要是后台要求的数据结构比较坑