1
免責事項:私はAureliaを非常に新しくしているので、これは明らかな質問かもしれません。Aurelia:アクティブ化中にビューモデルのプロパティを設定するには?
私は、Aureliaビューモデルでプロパティを設定しようとしているときにjavascriptスコープの問題が発生しています。次のコードでは、私のAPIコールが完了し、activateメソッドで約束を入力すると、 'this'は定義されていません。私がここで間違っていることに関するアイデアは?
import {inject} from "aurelia-framework";
import {HttpClient} from "aurelia-http-client";
@inject(HttpClient)
export class ListTasks{
constructor(httpClient) {
this.http = httpClient;
this.tasks = [];
}
activate() {
this.http.get('api/task').then(function(result){
// 'this' is undefined in the scope of this function
this.tasks = result.content;
});
}
}