本文介绍了复合组件属性中的枚举值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题很简单:我想创建一个具有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>那将是你最好的选择.
更多推荐
复合组件属性中的枚举值
发布评论