聚合物克隆对象 [英] Polymer Clone Objects
本文介绍了聚合物克隆对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何在Polymer中克隆对象?
How can we clone an object in Polymer?
示例
this.colorsAsc.push({color: 'red'});
this.colorsDesc = this.colorsAsc.reverse();
this.colorsDesc[0].color = 'blue'; // Both will be blue doing this
I can do it in these many functionalities What is the most efficient way to deep clone an object in JavaScript? but I wonder if there is a way in Polymer to do that?
Angular做到了 https://docs.angularjs.org/api/ng/function/angular.copy
Angular does it https://docs.angularjs.org/api/ng/function/angular.copy
推荐答案
您可以尝试以下技巧:
this.colorsDesc = JSON.parse(JSON.stringify(this.colorsAsc.reverse());
这篇关于聚合物克隆对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文