复合组件属性中的枚举值 [英] Enum values in Composite Component attribute

查看:110
本文介绍了复合组件属性中的枚举值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单:我想创建一个具有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>

那将是你最好的选择.

这篇关于复合组件属性中的枚举值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆