【发布时间】:2013-02-27 18:15:33
【问题描述】:
任何人都可以发布一个在打字稿中扩展可观察到的示例吗? 淘汰赛延长器:http://knockoutjs.com/documentation/extenders.html
我从 2013 年 3 月 6 日开始使用这个版本的 knockout.d.ts https://github.com/borisyankov/DefinitelyTyped/tree/master/knockout
编辑: 非常感谢!因此,要扩展您“只需”添加接口 KnockoutExtenders 以便打字稿将“允许”它。示例
interface KnockoutExtenders {
logChange(target: any, option: string): KnockoutObservableAny;
}
ko.extenders.logChange = function (target, option) {
target.subscribe(function (newValue) {
console.log(option + ": " + newValue);
});
return target;
};
在视图模型中声明如下:
this.score = ko.observable(score).extend({ logChange: "score" });
【问题讨论】: