私はactive
を私のクラスに定義します。 Dragulaコード内のactive
の値にアクセスしたいと思います。私がconsole.log
私のthis.active
私はundefined
を得るとき。私のコードのこの時点では、this
は私のクラスの開始時に宣言した変数ではなく、私のDragulaオブジェクトを参照しているようです。dragulaService.setOptions内のthisの値にアクセスする
Dragulaコード内でactive
の値にアクセスするにはどうすればよいですか?
export class GamePage {
active = [];
inactive = [];
constructor() {
this.dragulaService.setOptions('drop-'+this.tableID, {
revertOnSpill: true,
direction: 'horizontal',
moves: (el, source, handle, sibling) => this.checkPlayerCanBeDragged(el.id),
accepts: function (el, target, source, sibling) {
console.log('inactive', this.inactive);
return true;
}
});
}
}
https://stackoverflow.com/questions/34361379/arrow-function-vs-function:あなたは "この" のいずれかのJavascriptのbindメソッドまたはコールバックとをバインドする必要があります-declaration-expressions-are-they-equivalent-exch –
TL; DR:定義:太い矢印の機能を使用して定義する –