我正在尝试从 json 文件中获取组件的名称,并通过添加'this'
到其名称的方法。
import { MyComponent } from './Mycomponent';
...
MyComponent = MyComponent;
data = [
{
"name": "MyComponent"
}
];
方法:
test(name: any) {
return this.[name];
}
用法示例:
this.test('MyComponent');
预期输出为:
this.MyComponent
当我尝试:this.[name]
我得到了预期的标识符。
我怎样才能解决这个问题?