2017-02-09 55 views
0

我想将item变量dynamic添加到此属性中,例如如果该项目有35价值将成为this.BookingConfirmationFormsState35将动态变量添加到此属性

onChange(event, item){ 
    console.log(this.BookingConfirmationFormsState+item); // Doesn't work 
} 

回答

1

你需要使用括号符号[]访问动态属性名称:

this['BookingConfirmationFormsState' + item]; 

对于item = 35,上面的代码就相当于到:

this.BookingConfirmationFormsState35 
1
onChange(event, item){ 
    console.log(this['BookingConfirmationFormsState' + item]); 
}