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

后端 未结 8 1617
被撕碎了的回忆
被撕碎了的回忆 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:47

    Use data-bind something like this:

    data-bind="click:$parent.deleteItem.bind($parent)"
    

    Assign this to that as shown below

    public deleteItem(itemToDelete) 
    {
        var that = this;
        // remove item from list
        that.emails.remove(itemToDelete); 
    }
    

提交回复
热议问题