2017-09-29 49 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

相關問題