2017-09-29 44 views
0

我有一个基本订单输入表单,其中包含帐单和送货地址字段(均基于“地址”模型)。我有一个复选框,上面写着“帐单地址和发货一样?”如果选中,则会将帐单地址数据复制到送货地址。余烬:将模型数据复制到另一个

enter image description here

我会怎么做呢?这对我来说不是很明显。我在考虑点击“下一步”按钮时,如果“billShipSame”值= true,则复制数据。但是,您如何实际复制数据?或者我刚刚接近这个问题错了?

这个模型看起来像:

export default DS.Model.extend(Validations, { 
    type: attr('string'), 
    firstName: attr('string'), 
    lastName: attr('string'), 
    address1: attr('string'), 
    address2: attr('string'), 
    city: attr('string'), 
    state: attr('string'), 
    country: attr('string'), 
    postalCode: attr('string'), 
    phone: attr('string') 
}); 

而且这里有我如何使用它们的精简版本:

billingAddress: computed(function() { 
    return this.get('store').createRecord('address', { type: 'billing'}); 
}), 

shippingAddress: computed(function() { 
    return this.get('store').createRecord('address', { type: 'shipping'});  
}), 

orderModel: computed(function() { 
    return this.get('store').createRecord('order', { 
     billingAddress: this.get('billingAddress'), 
     shippingAddress: this.get('shippingAddress') 
    }); 
}), 

回答

1

我建议有你“一样计费”单选按钮触发将数据复制到相应字段的操作。由一次有人这样点击下一个,你的数据模型是在良好的形状和你的提交动作可以围绕节能

编辑:

两个型号之间复制值这些最简单的方法如下:

shippingAddress.setProperties(billingAddress.getProperties('firstName','lastName')); // etc 

相信你应该处理好以后的事情......

+0

那么,“与计费相同”默认为yes(因为大多数购物者都会这样)。但我的问题是,从一个模型到另一个模型复制数据的语法是什么? – tarponjargon

+0

啊,没有意识到:-)更新了我的答案 – acorncom

相关问题