Nested repeats 编辑

Nested repeats

With the nested repeat construct you can have more than one repeat construct in each component depending on the definition of the component. Consider a nested repeat of two levels. For each element in the outer list (first repeat-list), you can create a repeat list for all elements of the inner list (second repeat-list). The StyleBook compiler supports up to three nested repeats. Each repeat level has repeat-item and repeat-index attributes associated with it. Both repeat-item and repeat-index attributes are optional. In addition, each repeat can also specify a repeat-condition.

Example:

parameters:

  -

      name: vips

      type: ipaddress[]

  -

      name: vip-ports

      type: tcp-port[]

components:

  -

      name: lbvservers-comp  

      type: ns::lbvserver

      repeat:

         repeat-list: $parameters.vips

         repeat-item: ip

         repeat:

              repeat-list: $parameters.vip-ports

              repeat-item: port

      properties:

         name: str("lb-") + str($ip) + '-' + str($port)

         servicetype: HTTP

         ipv46: $ip

         port: $port
<!--NeedCopy-->

In this example, for each item in $parameters.vips, we iterate over all the items of $parameters.vip-ports. Thus, for each ipaddress specified in $parameters.vips, we create lbvserver configuration objects for all ports specified in $parameters.vip-ports. The properties section defines the name of the object with “lb” as a prefix for the combination of the IP address and the port. Therefore, for each iteration, $ip + $port defines a unique combination of the IP address and the port number.

If the repeat-item attribute is not provided, the compiler generates a default value for it. The default values for repeat-item are: $repeat-item, $repeat-item-1, $repeat-item-2 respectively for each repeat level. Similarly, if the repeat-index attribute is not provided, the compiler generates a default value for it. The default values for repeat-index are: $repeat-index, $repeat-index-1, and $repeat-index-2 respectively for each repeat level.

The following example describes the naming convention in the absence of repeat-item and repeat-index attributes in a nested repeat object.

Example:

components:

-

     name: lbvservers-comp  

     type: ns::lbvserver

     repeat:

         repeat-list: $parameters.vips

         repeat:

            repeat-list: $parameters.vip-ports

     properties:

        name: str("lb-") + str($repeat-item) + '-' + str($repeat-item-1)

        servicetype: HTTP

        ipv46: $repeat-item

        port: $repeat-item-1
<!--NeedCopy-->

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:65 次

字数:3480

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文