我正在使用yeoman-generator,我需要将一个数组的值传递给模板文件,例如我想将一个文本值数组传递给模板。
install() {
async app() {
let array = ['abc','cde','efg'];
this.fs.copyTpl(
this.templatePath('base','/abc.ts'),
this.destinationPath('example/abc.ts'),
{'array':array}
);
} // app
}// install
在.ts文件中,我定义了一个变量,用来接收传递过来的数组。
public options = <%= array %> ;
我的预期结果是
public options = ['abc','cde','efg'] ;
但结果是
public options = abc,cde,efg ;
如何解决这个问题?
在index.js中,数组变量显示为
让数组=['abc','cde','efg']。
然后在模板文件中,如果你想显示['abc','cde','efg'],而不是abc,cde,efg,你只需要在模板文件中写上以下代码
[<%= array.map(value => '${value}'
).join(',') %>]