TypeScript and Knockout binding to 'this' issue - lambda function needed?

后端 未结 8 1656
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 18:28

I\'ve been creating a htmlHelper function using TypeScript and KnockoutJS to edit a list of emails.

The list of emails is a Knockout ObservableArray called e

8条回答
  •  误落风尘
    2020-12-04 18:34

    to add my 2 cents, there's also a dirty way, that leverages the variable _this created by the Typescript compiler to keep a reference on this :

    public deleteItem(emailToDelete: string) {
        var that = eval('_this');
        // remove item from list
        that.emails.remove(emailToDelete); // remove? in JS,  really? 
    }
    

提交回复
热议问题