angular,,以及深度拷贝问题;JSON.parse,JSON.stringify灵活运用

问题:

$scope.list = [];
$scope.listTree = {};
$scope.dataTree = [];
//获取listTree的数据
$scope.getList = function () {
serviceStruct.getAll({},path).then(function (res) {
$scope.listTree = res.data || res.data.result;
getGroup($scope.listTree);
}).then(function(){
$scope.load = true;
});
}
省略若干
……………………………………………………
list,dataTree数组的数据都是从listTree数据中push;现改变list数据,listTree,dataTree的数据也会被更改,
解决此问题就考虑到slice拷贝,亲测不好使,咱没分析原因,另外一种解决方案如下图:
JSON.parse1,JSON.stringify灵活运用,简单实现了slice拷贝

 

posted @ 2018-05-11 10:42  janice_jia  阅读(791)  评论(1编辑  收藏  举报