JSFiddle:http: //jsfiddle.net/abepark/rzeNC/7/
在您从自动完成下拉列表中选择一个选项后,我遇到了 ko.observable 属性 Job.CompanyName 没有更新的问题。
无论如何要在不创建自定义活页夹的情况下更新 ko.observable 属性?
var model = {
Job: {
CompanyName: "Test"
}
};
var InterviewViewModel = function (data) {
ko.mapping.fromJS(data, {}, this);
this.add = function (data) {
console.log("click");
console.log(this.Job.CompanyName());
}.bind(this);
}
$("#CompanyName").autocomplete({
source: ["Test", "cool", "what", "Example", "Cookies"]
});
var viewModel = new InterviewViewModel(model);
ko.applyBindings(viewModel);
viewModel.Job.CompanyName.subscribe(function (val) {
console.log(val);
});