【发布时间】:2013-12-28 12:30:13
【问题描述】:
我对 knout 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) {
}
}
如何绑定到 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>
【问题讨论】:
标签: javascript html data-binding knockout.js