我有显示两个不同的数据集的一个观点: 假设proposalDetails和订单明细。 我继承了一些试图将这两个类作为成员备份的代码。参考在奥里利亚
在下面的评论代码的问题是,该类功能不被克隆。只有成员。在另一方面保持2班作为参考,当我来回切换
(proposalDetails和订单明细之间)的作品就好了是否有一个原因,保持基准是坏的/不正确的做法?
有危险,当我修改proposalDetails,ORDERDETAILS太修改?
switchView(viewName) {
if (viewName === 'proposal') {
//this.orderBackup = JSON.parse(JSON.stringify(this.orderDetails));
//this.orderDetails = JSON.parse(JSON.stringify(this.proposalDetails));
//'Cloning' the member like this does not include all the class functions
//I changed it to keep just the reference
this.orderBackup = this.orderDetails;
this.orderDetails = this.proposalDetails;
$('#view_ordered').removeClass('active');
$('#view_proposal').addClass('active');
this.formDisabled = true;
return;
}
this.orderDetails = this.orderBackup;
}
这没有任何意义。如果你改变'orderDetails',你也会改变'orderDetailsBackup'。 –
@fabioLuz感谢您指出了这一点。我更正了示例 – Spiff