【问题标题】:Is it possible to nest YAML anchors hierarchically?是否可以分层嵌套 YAML 锚?
【发布时间】:2022-01-07 00:37:17
【问题描述】:

我是使用 YAML 的新手。我想知道是否可以像我在下面的示例中尝试的那样“嵌套”YAML 锚点。不幸的是,我收到一个错误YAMLException: unidentified alias "foo" at line 13, column 19: category: *foo ^

namespace: &namespace-definition
  name: "Hellow world"
  value: "hw"
categories: &categories
  - &foo:
    name: "foo"
    namespace: *namespace-definition
  - &bar:
    name: "bar"
    namespace: *namespace-definition
keys:
  - name: "element1"
    category: *foo
  - name: "element2"
    category: *bar

还有其他方法可以实现我想要做的事情,还是不可能?

【问题讨论】:

    标签: yaml


    【解决方案1】:

    您示例中的锚点命名为 foo:bar:,而不是 foobar

    去掉后面的冒号就可以了:

    namespace: &namespace-definition
      name: "Hellow world"
      value: "hw"
    categories: &categories
      - &foo
        name: "foo"
        namespace: *namespace-definition
      - &bar
        name: "bar"
        namespace: *namespace-definition
    keys:
      - name: "element1"
        category: *foo
      - name: "element2"
        category: *bar
    

    【讨论】:

      猜你喜欢
      • 2014-08-30
      • 1970-01-01
      • 2016-08-31
      • 2020-03-01
      • 2014-04-14
      • 1970-01-01
      • 2023-01-19
      • 2014-02-20
      • 2015-02-13
      相关资源
      最近更新 更多