如何使用Typescript使用装饰器扩展knockout observable?

时间:2015-11-22 18:42:46

标签: knockout.js typescript decorator

如何使用Typescript使用装饰器扩展knockout observable? 示例:使用装饰器进行验证。

interface Person {
    firstname:string;
}

class PersonViewModel {
    @required
    firstname = ko.observable<string>();
    constructor (person:Person) {
        // put this in an required decorators
        // this.firstname.extend({required:true})
        this.firstname(person.firstname);
    }
}

function required(target, key) {
    // ????
    // pseudo code extend Person Class variable firstname
    // ???firstname.extend({required:true})
}

0 个答案:

没有答案