我有一个视图模型
function ViewModel() {
this.applications = ko.observable(10);
this.applicationsText_computed = ko.computed(function () {
return "You have " + this.applications() + " applications";
});
this.applicationsText_classinc = function () {
return "You have " + this.applications() + " applications";
};
};
var viewModel = new ViewModel();
ko.applyBindings(viewModel);
<p data-bind="text: applicationsText_computed()"></p>
<p data-bind="text: applicationsText_classic()"></p>
applications
当我更改可观察时,这两个段落都会更改文本。
那么,使用 ako.computed
和 classinc 函数有什么区别呢?