更新时间:2023-12-02 20:21:10
当你从孩子那里调用一个方法时,此
将设置为子项而不是 $ parent
。
When you call a method from the child, this
will be set to the child rather than $parent
.
有很多方法可以确保使用适当的值调用
。一种简单的方法是使用 removeExpertise
.bind
。
There are many ways to ensure that removeExpertise
is called with the appropriate value for this
. An easy way is to use .bind
.
它看起来像:
this.removeExpertise = function (expertise) {
this.expertise.remove(expertise);
}.bind(this);
此外,您还需要专业知识
一个 observableArray
而不是 observable
,作为 observableArray
公开数组操作方法,包括 remove
函数。
Also, you will want expertise
to be an observableArray
rather than an observable
, as an observableArray
exposes array manipulation methods including a remove
function.