使用增量访问数组 Twilio Studio

Using an increment to access array Twilio Studio

为了这个问题,我正在使用两个小部件: 设置变量小部件,以及基于小部件的拆分。我想遍历我传入的数组 (flow.data.arr):

我正在尝试设置变量:

key: increment
value: {% if flow.variables.increment %}{{flow.variables.increment | plus:1}}{% else %}0{% endif %}

并在拆分中基于:

condition: flow.data.arr[increment].nestedValue isNotBlank

我已经用数字进行了测试,如果我插入 0 或 1,那么它就可以正常工作。我的假设是它将 increment var 评估为一个字符串,因为当我在 if 逻辑中包含空格时,它在字符串中添加了这些空格。

SO 如果我的假设是正确的,我怎样才能让 Twilio 将 increment 计算为一个数字?如果我的假设是错误的,我该如何实现这种“for 循环”式的迭代?

尽管 Twilio 应该将变量存储为数字,但 Twilio 会将其存储为字符串。在使用数字索引数组之前,您必须进行显式转换。

在分割基础上可以使用:

condition:
{% assign i=flow.variables.increment | plus:0 %}
{{flow.data.arr[i].nestedValue}} isNotBlank

达到预期的效果。添加 0 将在使用时将其转换为数字。