阵列类型的角度示意图提示

时间:2019-04-17 19:56:20

标签: angular angular-schematics

设置原理图时,我看到可以提示以下任何一种类型:String |布尔|数组|编号整数|空|对象。

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

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

虽然有大量的String和Boolean提示示例,但没有人提供我为Array提示找到的示例。为了我的一生,我无法弄清楚如何在数组中提供选项来提示用户选择,而这根本不会出现在他们的文档中。

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

3 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

ng new myProject

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

如果您查看@ 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                                             ]" }
    ]
  },

答案 2 :(得分:-1)

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

这意味着您将无法在列表中显示当前存在的模块。至少目前还没有(v9)