数组和列表函数 arrays

使用这些函数可以更轻松地与数组、列表和字符串进行交互。

仅计算null count-only-null

countOnlyNull函数用于计算列表中空值的数量。

语法

{%= countOnlyNull(array) %}

示例

{%= countOnlyNull([4,0,1,6,0,0]) %}

返回3。

Count With Null count-with-null

countWithNull函数用于对包含null值的列表的所有元素进行计数。

语法

{%= countWithNull(array) %}

示例

{%= countOnlyNull([4,0,1,6,0,0]) %}

返回6。

Distinct distinct

distinct函数用于从已删除重复值的数组或列表中获取值。

语法

{%= distinct(array) %}

示例

以下操作指定在多个商店下订单的人员。

{%= distinct(person.orders.storeId).count() > 1 %}

Distinct Count With Null distinct-count-with-null

distinctCountWithNull函数用于计算列表中包括null值的不同值的数量。

语法

{%= distinctCountWithNull(array) %}

示例

{%= distinctCountWithNull([10,2,10,null]) %}

返回3。

First item head

head函数用于返回数组或列表中的第一个项。

语法

{%= head(array) %}

示例

以下操作将返回价格最高的前五个订单中的第一个。 有关topN函数的更多信息,请参见数组中的第一个n

{%= head(topN(orders,price, 5)) %}

数组中的前n first-n

topN函数用于返回数组中的前N项(当根据给定的数值表达式按升序排序时)。

语法

{%= topN(array, value, amount) %}
参数
描述
{ARRAY}
要排序的数组或列表。
{VALUE}
要对数组或列表进行排序的属性。
{AMOUNT}
要返回的项目数。

示例

以下操作将返回价格最低的前五个订单。

{%= topN(orders,price, 5) %}

In in

in函数用于确定一个项是数组还是列表的成员。

语法

{%= in(value, array) %}

示例

以下操作定义3月、6月或9月拥有生日的人员。

{%= in (person.birthMonth, [3, 6, 9]) %}

Includes includes

includes函数用于确定一个数组或列表是否包含给定项。

语法

{%= includes(array,item) %}

示例

以下操作定义其最喜爱的颜色包括红色的人员。

{%= includes(person.favoriteColors,"red") %}

Intersects intersects

intersects函数用于确定两个数组或列表是否至少有一个公共成员。

语法

{%= intersects(array1, array2) %}

示例

以下操作定义其最喜爱的颜色至少包括红色、蓝色或绿色中的一种的人员。

{%= intersects(person.favoriteColors,["red", "blue", "green"]) %}

数组中的最后n

bottomN函数用于返回数组中的最后N项(当根据给定的数值表达式按升序排序时)。

语法

{%= bottomN(array, value, amount) %}
参数
描述
{ARRAY}
要排序的数组或列表。
{VALUE}
要对数组或列表进行排序的属性。
{AMOUNT}
要返回的项目数。

示例

以下操作将返回具有最高价格的最后5个订单。

{%= bottomN(orders,price, 5) %}

Not in notin

notIn函数用于确定一个项是否不是一个数组或列表的成员。

NOTE
notIn函数​ ​确保这两个值都不等于null。 因此,结果不是in函数的完全否定。

语法

{%= notIn(value, array) %}

示例

以下操作定义非三月、六月或九月的生日人员。

{%= notIn(person.birthMonth ,[3, 6, 9]) %}

Subset of subset

subsetOf函数用于确定一个特定数组(数组A)是否是另一个数组(数组B)的子集。 换句话说,数组A中的所有元素都是数组B的元素。

语法

{%= subsetOf(array1, array2) %}

示例

以下操作定义访问过他们喜欢的所有城市的人。

{%= subsetOf(person.favoriteCities,person.visitedCities) %}

Superset of superset

supersetOf函数用于确定一个特定数组(数组A)是否是另一个数组(数组B)的超集。 换句话说,该数组A包含数组B中的所有元素。

语法

{%= supersetOf(array1, array2) %}

示例

以下操作定义至少吃过一次寿司和比萨的人。

{%= supersetOf(person.eatenFoods,["sushi", "pizza"] %}
recommendation-more-help
b22c9c5d-9208-48f4-b874-1cefb8df4d76