我想我在這裏苦於基本知識。 代碼:訂閱不能與Knockout模型一起使用
var VehicleSearchViewModel = function() {
this.VehicleVariantId = ko.observable(0);
this.VehicleVariantId.subscribe(function (id) {
console.log(id);
});
};
從功能外的這,我做了以下內容:
VehicleSearchViewModel.VehicleVariantId = 777;
...和console.log
不火。儘管如果我在控制檯中鍵入VehicleSearchViewModel.VehicleVariantId
,我可以看到它已更新爲新值。做這件事的正確方法是什麼?
你究竟在哪裏綁定這個?我懷疑你是在爲你撥弄缺少'new'關鍵字 – 2013-04-05 16:03:17