1

我有一个带有 CRUD 操作的角度数据表的示例项目。我在 grunt web 上查看了 Project Scaffolding,但我找不到任何符合我需求的 JavaScript 模板...

我看到了我想要的 init.copyAndProcess,但我需要对此进行一些改进。首先,我想要在我的 js 文件中带有条件句的模板,例如(伪代码):

{if prop.selectAllButton} 
//declare header render on Datatables in several lines of code{/if}

此外,将有 10 或 20 个选项,它可能会随着列数或通过创建虚拟列而增长。因此,我希望 props 对象位于文件中,而不是 cli 上的提示。

该表不是以角度方式呈现的。

提前致谢。志。

4

1 回答 1

1

现在我看到,如果我离开 grunt Scaffolding 并使用 yeoman,我的问题很容易回答......

在 yo 文件中,我可以在初始化阶段读取我的 configFile,例如:

 initializing: function () {
    this.pkg = require('../package.json');
    this.dtconfig = require(this.options['config-file-location']);
},

其中 'config-file-location' 是 cli 的参数。

他们,在写作阶段,我使用 dtconfig 作为 copyTpl 的参数:

  scripts: function () {
  this.fs.copyTpl(
    this.templatePath('main.js'),
    this.destinationPath('app/scripts/main.js'),
    {//Parameters
      selectAllButton: this.dtconfig.selectAllButton
     }
  );

而他们,在 templates/main.js 文件中:

<% if (selectAllButton) { %>
//apply selectaAll header render for dt.
于 2016-02-15T13:20:27.237 回答