如何在 DXL 脚本中使用枚举?
我想测试 DOORs 对象的枚举属性的值。这怎么能做到呢?在哪里可以找到描述此类基本功能的 DXL 文档?
if (o."Progress" == 0) // This does NOT work
{
// do something
}
I'd like to test the value of an enumeration attribute of a DOORs object. How can this be done? And where can I find a DXL documentation describing basic features like this?
if (o."Progress" == 0) // This does NOT work
{
// do something
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
因此,经过两周和过期的赏金,我终于成功了。
可以根据需要将枚举属性分配给 int 或 string 变量。但是您必须分配给一个变量才能执行此类转换。当像我的示例中那样进行简单比较时,它不会被转换。因此,解决方案如下:
当 tmp 是字符串时,可以与枚举文字进行比较。
那很容易。不是吗?和 在这里我终于找到了有关 DXL 手册的所有信息。
So after two weeks and an expired bounty I finally made it.
Enum-Attributes can be assigned to int or string variables as desired. But you have to assign to a variable to perform such a conversion. It is not casted when a mere comparison is done like in my example. So here comes the solution:
When
tmp
is a string, a comparison to the enum literals is possible.That was easy. Wasn't it? And here I finally found the everything-you-need-to-know-about-DXL manual.
对于多值枚举,最好的方法是
if (isMember(o."Progress", "0")) {
。单个和多个枚举变量的可能枚举被视为字符串,因此 Steve 的解决方案是单个枚举的最佳 dxl 方式。For multi-valued enumerations, the best way is
if (isMember(o."Progress", "0")) {
. The possible enumerations for single and multi-enumeration variables are considered strings, so Steve's solution is the best dxl way for the single enumeration.您还可以执行
此操作,将属性值转换为字符串并将其与字符串
"0"
进行比较You can also do
This will cast the attribute value to a string and compare it to the string
"0"
如果您正在谈论可从“编辑类型”框分配的“相关数字”,那么您需要首先获取枚举字符串在枚举中的位置,然后检索
EnumName[k].value
。我不是 DXL 方面的专家,因此找到我所知道的索引的唯一方法是循环
1 : EnumName.size
,当你得到与枚举字符串,使用该循环索引值来检索枚举“相关编号”。If you're talking about the "related number" that is assignable from the Edit Types box, then you'll need to start by getting the position of the enumeration string within the enum and then retrieve
EnumName[k].value
.I'm no expert at DXL, so the only way to find the index that I know of off the top of my head is to loop over
1 : EnumName.size
and when you get a match to the enumeration string, use that loop index value to retrieve the enumeration "related number."