我有两个送货类型的表格(包括姓名、地址、邮政编码等),还有一个按钮,上面写着“送货地址与送货地址相同”。基本上我试图做到这一点,以便当用户单击该按钮时,来自第一个字段的相同可观察值随后与第二个字段共享。我如何解决这个问题(可能是非常错误的)是通过设置两组可观察的,如下所示:
self.firstName = ko.observable("");
self.lastName = ko.observable("");
self.phoneNumber = ko.observable("");
self.address1 = ko.observable("");
self.address2 = ko.observable("");
self.city = ko.observable("");
self.state = ko.observable("");
self.postcode = ko.observable("");
self.delFirstName = ko.observable("");
self.delLastName = ko.observable("");
self.delPhoneNumber = ko.observable("");
self.delAddress1 = ko.observable("");
self.delAddress2 = ko.observable("");
self.delCity = ko.observable("");
self.delState = ko.observable("");
self.delPostcode = ko.observable("");
然后我尝试设置一个功能,单击该功能时,将共享运输详细信息。
self.sameDelAddress = function() {
self.delFirstName() = self.firstName(self.firstName);
self.delLastName() = self.lastName(self.lastName);
self.delPhoneNumber() = self.phoneNumber(self.phoneNumber);
self.delAddress1() = self.address1(self.address1);
self.delAddress2() = ko.observable(self.address2);
self.delCity() = ko.observable(self.city);
self.delState() = ko.observable(self.state);
self.delPostcode() = ko.observable(self.postcode);
}