我正在创建一个包含帐单和送货地址字段的表单。当用户选中“相同地址”时,我想在帐单地址和送货地址之间创建绑定;当未选中该框时,我想断开该绑定。
HTML:
{{#with billingAddress}}
{{view Ember.TextField valueBinding="firstName"}}
{{view Ember.TextField valueBinding="lastName"}}
{{/with}}
{{view Ember.Checkbox checkedBinding="view.isSameAddress"}}
{{#with shippingAddress}}
{{view Ember.TextField valueBinding="firstName"}}
{{view Ember.TextField valueBinding="lastName"}}
{{/with}}
JavaScript:
App.AddressesRoute = Ember.Route.extend({
model: function() {
return {
billingAddress: Checkout.BillingAddress,
shippingAddress: Checkout.ShippingAddress
};
}
});
App.AddressesView = Ember.View.extend({
isSameAddress: false,
useSameAddress: function() {
if (this.isSameAddress) {
// bind billing and shipping addresses
} else {
// remove binding
}
}.observes('isSameAddress')
});
App.Address = Ember.Object.extend({
firstName: null,
lastName: null
});
App.Billing = App.Address.create({
firstName: 'John',
lastName: 'Doe'
});
App.Shipping = App.Address.create({
firstName: '',
lastName: ''
});
我试过使用Ember.Binding
, 以及其他一些没有运气的方法。我已经能够将运费设置为计费,但没有绑定,模板也没有更新。
任何帮助或朝着正确方向轻推将不胜感激!