【发布时间】:2012-09-23 06:32:39
【问题描述】:
有没有使用 TypeScript 和 KnockoutJS 的示例?我只是好奇他们将如何合作?
编辑
这是我所拥有的,似乎可以工作
declare var ko: any;
declare var $: any;
class ViewModel {
x = ko.observable(10);
y = ko.observable(10);
}
$(() => {
ko.applyBindings(new ViewModel());
});
这会生成以下 Javascript:
var ViewModel = (function () {
function ViewModel() {
this.x = ko.observable(10);
this.y = ko.observable(10);
}
return ViewModel;
})();
$(function () {
ko.applyBindings(new ViewModel());
});
【问题讨论】:
-
我对与“var”结合使用的“declare”关键字感到有些困惑,直到我在规范中找到关于环境声明的部分。现在很有意义:typescriptlang.org/Content/….
-
在 Typescript 0.9 中,我们有泛型,它为您提供输入的 observables:
ko.observable<number>(10)。我写了一篇博文,提供了一些更详细的信息:ideasof.andersaberg.com/idea/12/…