5

在设置我的原理图时,我看到我可以提示输入以下任何类型 String | 布尔值 | 数组 | 号码 | 整数 | 空 | 目的。

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

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

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

{
  "$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"]
}
4

3 回答 3

4

您可以尝试以下方法,也可以检查适合您的选项。

"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"
        ]
      }
    }

于 2019-04-17T21:02:32.583 回答
2
ng new myProject

将提示您设置样式,这是您可以从中选择的列表。

如果您查看 @angular/cli 项目 ( \packages\schemics\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                                             ]" }
    ]
  },
于 2019-05-07T10:27:26.710 回答
-1

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

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

于 2020-05-03T15:08:18.107 回答