使用通用表达式语言(CEL)在列表中查找值的示例

问题描述 投票:1回答:2

我遵循谷歌常用表达式语言规范,如果我能做这样的事情可以指导我:

我需要编写一个表达式来查找使用谷歌CEL在phone_numbers列表中是否“345”。

json :  {"phone_numbers": ["123","234","345"] }

example :  phone_numbers.exist_one("345"); // this does not works .... 

https://github.com/google/cel-spec/blob/master/doc/langdef.md#standard-definitions

expression dynamic-execution
2个回答
0
投票

我得到了表达式:

phone_numbers.exists_one(r, r=="345")


0
投票

由于您只是测试列表中是否存在单个值,我建议使用in运算符:

'345' in phone_numbers

如果exists_one只能在列表中出现一次,那么'345'宏非常有用。

© www.soinside.com 2019 - 2024. All rights reserved.