如何在ytt中将地图添加到地图数组中?

时间:2020-10-23 17:33:56

标签: yaml ytt

我正在尝试将地图添加到ytt中的地图数组中,以修改YAML文档。

我尝试了以下操作,但出错了,并说它期望有一个映射,但得到一个数组。

https://gist.github.com/amalagaura/c8b5c7c92402120ed76dec95dfafb276

---
id: 1
type: book
awards:
  books:
  - id: 1
    title: International Botev
    reviewers:
      - id: 2
        name: PersonB
  - id: 2
    title: Dayton Literary Peace Prize
    reviewers:
      - id: 3
        name: PersonC
        
#! How do I add a map to an array of maps?
#@ load("@ytt:overlay", "overlay")

#@overlay/match by=overlay.all
---
awards:
  books:
    #@overlay/match by=overlay.all, expects="1+"
    #@overlay/match missing_ok=True
    reviewers:
      #@overlay/append
      - id: 1
        name: PersonA
      

1 个答案:

答案 0 :(得分:2)

<!--Put this before your </body> tag-->
<script>
// Add a click event listener to the element the id refers to
document.getElementById("menu-item-id").addEventListener("click", function() {
   // Get descriprion reference
   let description = document.getElementById("menu-item-description");
   // If description is visible hide it
   if (description.style.display !== "none") {
      description.style.display = "none";
   }
   // If description is not visible show it
   else {
      description.style.display = "block";
   }
});
</script>

您真的很接近解决方案,您真正需要的只是使#@ load("@ytt:overlay", "overlay") #! Add a map to an array of maps: #@overlay/match by=overlay.all --- awards: books: #@overlay/match by=overlay.all, expects="1+" - reviewers: #@overlay/append - id: 1 name: Person A 成为数组项。如果要向没有该键的书中添加审阅者,则必须在数组项和地图项上添加匹配项;下面包含要点,以查看此行为在实际操作中的叠加。 如果同一项目上有多个reviewers注释,则最后一个赢。有计划改善这种行为:https://github.com/k14s/ytt/issues/114

https://get-ytt.io/#gist:https://gist.github.com/gcheadle-vmware/a6243ee73fa5cc139dba870690eb15c5