如果条件失败,表达式太复杂

编程入门 行业动态 更新时间:2024-10-21 16:12:45
本文介绍了如果条件失败,表达式太复杂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个条件语句声称'表达式太复杂,无法在合理的时间内解决。如果在我的条件中有超过5个包含语句,它会失败的那个错误。这似乎不应该发生在编译,看到作为语句不是那么复杂。这是其他人遇到的错误吗?除了分裂我的条件,有没有解决方案?

I have a conditional statement that claims the 'Expression was too complex to be solved in reasonable time. If there are any more than around 5 contains statements in my conditional, it fails with that error. This does not seem like something that should be happening on compile, seeing as the statement isn't all that complex. Is this a bug that anyone else has run into? Is there a solution other than splitting up my conditions?

else if( contains(JSONDict.keys.array, "id") && contains(JSONDict.keys.array, "part_number") && contains(JSONDict.keys.array, "sales_part_number") && contains(JSONDict.keys.array, "include_in_search") && contains(JSONDict.keys.array, "description") && contains(JSONDict.keys.array, "brand") && contains(JSONDict.keys.array, "product_group") && contains(JSONDict.keys.array, "product_design") && contains(JSONDict.keys.array, "material") && contains(JSONDict.keys.array, "line") && contains(JSONDict.keys.array, "unit_of_mass") && contains(JSONDict.keys.array, "coating") && contains(JSONDict.keys.array, "pcs_converstion") && contains(JSONDict.keys.array, "appRim") && contains(JSONDict.keys.array, "appSegment") && contains(JSONDict.keys.array, "series") && contains(JSONDict.keys.array, "product_application") ){ }

推荐答案

是的,这是一个已知问题 - 另请参见此答案。

Yes that's a known issue - see also this answer.

解决方案是使用多行语句将逻辑表达式存储到变量中:

The solution is to store the logical expression into a variable, using a multiline statement:

else { var logicalExpression = contains(JSONDict.keys.array, "id") && contains(JSONDict.keys.array, "part_number") && contains(JSONDict.keys.array, "sales_part_number") && contains(JSONDict.keys.array, "include_in_search") logicalExpression = logicalExpression && contains(JSONDict.keys.array, "description") && contains(JSONDict.keys.array, "brand") && contains(JSONDict.keys.array, "product_group") && contains(JSONDict.keys.array, "product_design") // ... etc. if logicalExpression { } }

对于这么强大的语言来说有点奇怪...但是这是一个(希望暂时的)折衷。

A little weird for such a powerful language... but it's a (hopefully temporary) trade off.

更多推荐

如果条件失败,表达式太复杂

本文发布于:2023-11-28 15:31:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642967.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   太复杂   条件

发布评论

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

>www.elefans.com

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