Parent reference 编辑
If you are using nested components, you can refer to the parent component using the $parent notation. If the parent component builds multiple configuration objects using the repeat construct, and within each iteration, child components build other configuration objects, then the $parent notation always refers to the current iteration of the parent component. For example, $parent.properties.name refers to the name property of the configuration object built in the current iteration by the parent.
Example:
components:
-
name: my-lbvserver-comp
type: ns::lbvserver
properties:
name: $parameters.name + "-lb"
servicetype: HTTP
ipv46: $parameters.ip
port: 80
lbmethod: $parameters.lb-alg
components:
-
name: my-svcg-comp
type: ns::servicegroup
properties:
name: $parameters.name + "-svcgrp"
servicetype: HTTP
components:
-
name: lbvserver-svg-binding-comp
type: ns::lbvserver_servicegroup_binding
properties:
name: $parent.parent.properties.name
servicegroupname: $parent.properties.name
-
name: members-svcg-comp
type: ns::servicegroup_servicegroupmember_binding
repeat: $parameters.svc-servers
repeat-item: srv
properties:
ip: $srv
port: str($parameters.svc-port)
servicegroupname: $parent.properties.name
<!--NeedCopy-->
You can also navigate upward through the hierarchy of components by accessing the properties of the parents of parents all the way to top-level components. For example, the property name of the component lbvserver-svg-binding-comp takes its value from the property name of the parent of its parent, the my-lbvserver-comp component, by using the $parent.parent notation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论