嘿,有人能告訴我如何在foreach循環中訪問組件變量? 這裏我 PlunkerTypescript如何訪問foreach循環中的組件變量?
public testVariable:number;
test(){
console.log('fired');
var x =[1,2,3,4];
x.forEach(function (e){
this.testVariable = e;
})
console.log(this.testVariable);
}
[如何在回調中訪問正確的\'this \'上下文?](https://stackoverflow.com/questions/20279484 /如何訪問這個正確的回調這個上下文) – echonax