Angular 阵列类型的示意图提示

Angular Schematics Prompt for array type

设置原理图时,我发现可以提示输入以下任何类型布尔值 |数组 |编号 |整数 |空 |对象。

我正在尝试设置一个示意图,提示用户 select 从可用模块列表中选择一个模块。因此,例如用户会看到这样的内容:

What module are you adding this store to?
 > Foo
   Bar
   Baz

虽然有大量关于字符串和布尔提示的示例,但没有人提供我为数组提示找到的示例。对于我的生活,我无法弄清楚如何在数组中提供选项以提示用户从 select 开始,这根本没有出现在他们的文档中。

{
  "$schema": "http://json-schema.org/schema",
  "id": "SchematicsIDXStoreGen",
  "title": "IDX Store Gen Schema",
  "type": "object",
  "properties": {
    "featureName": {
      "type": "string",
      "description": "The name of the store",
      "x-prompt": "What is the name of the store you'd like to create"
    },
    "module": {
      "type": "array",
      "description": "Select the appropriate module",
      "x-prompt": "What module are you adding this store to?" // I want to provide a list of available modules here.
    }
  },
  "required": ["featureName", "module"]
}

你也可以试试下面的方法,看看哪个适合你。

"modules": {
      "type": "array",
      "description": "description",
      "uniqueItems": true,
      "items": {
        "type": "string"
      },
      "x-prompt": {
        "message": "Which module would you like to select?",
        "type": "list",
        "multiselect": true,
        "items": [
          "firstOption",
          "secondOption",
          "thirdOption"
        ]
      }
    }

ng new myProject

将提示您设置样式,这是一个列表,您可以从中select。

如果您查看@angular/cli 项目 (\packages\schematics\angular\ng-new), 你可以看看他们是怎么做到的:

"style": {
  "description": "The file extension or preprocessor to use for style files.",
  "type": "string",
  "default": "css",
  "enum": [
    "css",
    "scss",
    "sass",
    "less",
    "styl"
  ],
  "x-prompt": {
    "message": "Which stylesheet format would you like to use?",
    "type": "list",
    "items": [
      { "value": "css",  "label": "CSS" },
      { "value": "scss", "label": "SCSS   [ http://sass-lang.com/documentation/file.SASS_REFERENCE.html#syntax ]" },
      { "value": "sass", "label": "Sass   [ http://sass-lang.com/documentation/file.INDENTED_SYNTAX.html       ]" },
      { "value": "less", "label": "Less   [ http://lesscss.org                                                 ]" },
      { "value": "styl", "label": "Stylus [ http://stylus-lang.com                                             ]" }
    ]
  },

不幸的是,none 这些答案完全解决了这个问题。是的,您可以在 x-prompt 属性 中使用枚举和多个项目显示选项列表,如上面的答案所示,但它是一个 JSON 文件,它必须是一个硬编码的值列表。

这意味着您将无法在列表中显示当前存在的模块。至少现在不是 (v9)