我是一個相對較新的使用淘汰賽JavaScript庫。我有一個問題,得到一個可觀察的屬性,這是另一個對象的對象。這裏是我的代碼:JavaScript淘汰賽的綁定嵌套對象不工作
function Customer(id) {
var self = this;
self.customer_id = ko.observable(id);
self.custnum = -1;
self.busname = ko.observable("");
self.address = "";
self.city = "";
self.state_id = "";
self.zipcode = "";
self.cnt_sal_id = "";
self.cnt_first_name = "";
self.cnt_last_name = "";
self.cnt_title = "";
//alert("customer: " + self.customer_id());
}
var CustomerEntryViewModel = function(date) {
var self = this;
self.last_update = ko.observable(date);
self.customer = ko.observable(new Customer(""));
self.addCustomer = function (id) {
var c = new Customer(id);
self.customer = c;
alert("New id: " + self.customer.customer_id() + " num: " + c.custnum);
}
self.customerSearch = function() {
}
self.editCustomer = function (customer_id) {
}
self.save = function(customer) {
}
}
我該如何去約束客戶對象中的屬性。我嘗試用典型的JavaScript點符號,像這樣:customer.customer_id
這裏是結合數據的HTML:
<div class="field-input" style="margin-bottom:10px;">
<input type="text" id="customer_id" style="width:100%;"
data-bind="jqxInput: { placeHolder: 'Customer #', value:
customer().customer_id, height: 21, width: 208,
minLength: 1, disabled: true }"/>
</div>
@ user2864740 - 嗯,這個http://knockoutjs.com/documentation/custom-bindings-c ontrolling-descendant-bindings.html看起來很酷。添加到我的閱讀列表:) –
亞當,感謝您的迴應。信不信由你,這部分工作:alert(「New id:」+ self.customer.customer_id()+「num:」+ c.custnum);但是,相同的引用不能在我的html綁定中工作。 – user3088317