复合组件属性中的枚举值

编程入门 行业动态 更新时间:2024-10-23 00:23:20
本文介绍了复合组件属性中的枚举值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的问题很简单:我想创建一个具有String属性Type的复合组件.

My issue is quite simple : I want to create a composite component with a String attribute, Type.

<cc:attribute name="type" /> 此属性将具有3个可接受的值,[TYPE1,TYPE2,TYPE3]

<cc:attribute name="type" /> This attribute will have 3 acceptable values, [TYPE1, TYPE2, TYPE3]

是否可以说我的组件将仅接受这些值?

Is it possible to say my component will accept only these values ?

推荐答案

不幸的是,您不能在cc接口中的复合组件属性值上设置编译/构建时间限制.但是,您可以通过检查cc实现中的值来设置运行时限制.

Unfortunately no, you cannot put a compile/buildtime restriction on a composite component attribute value in the cc interface. You can however put a runtime restriction by checking the value in the cc implementation.

<ui:param name="type" value="#{cc.attrs.type}" /> <ui:fragment rendered="#{type == 'TYPE1' or type == 'TYPE2' or type == 'TYPE3'}"> <p>The type is TYPE1, TYPE2 or TYPE3.</p> <p>Write your component's body here.</p> </ui:fragment>

那将是你最好的选择.

更多推荐

复合组件属性中的枚举值

本文发布于:2023-10-24 17:04:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524510.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组件   属性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!