You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Power Automate中过滤含指定地点的Trip数组?

解决方案步骤

1. 过滤包含目标地点的Trip对象

使用Filter Array动作,按以下配置操作:

  • 输入:选择Create TripsArray动作的输出(即body('Create_TripsArray'))
  • 过滤条件:使用以下表达式判断当前Trip的Stops中是否存在目标地点:
    length(intersection(item()?['Stops']?[*]?['Location'], outputs('Compose_TargetPlaces'))) > 0
    
    逻辑说明:
    • item()?['Stops']?[*]?['Location']:提取当前Trip下所有Stops的Location,生成字符串数组
    • intersection(...):计算该Location数组与目标地点数组的交集
    • length(...) > 0:若交集长度大于0,说明当前Trip包含目标地点,保留该对象

2. 提取仅含Trip名称的数组

使用Select动作,处理Filter Array的输出:

  • 输入:选择Filter Array动作的输出
  • 映射:添加一个键Trip,值设置为item()?['Trip']
    完成后,Select的输出即为你需要的格式:[{"Trip": "My second Trip"}, {"Trip": "My Last Trip"}]

3. 统计符合条件的Trip数量

使用length()函数统计Select输出的数组长度,表达式为:

length(body('Select'))

原表达式错误原因

你之前的表达式存在两个核心问题:

  1. body('Create_TripsArray')是数组类型,不能直接通过['Trip']访问属性,必须通过遍历数组元素(item())来访问单个Trip对象的属性
  2. 访问层级错误,正确的层级应该是item()?['Stops'],而非item()?['Trip']?['Stops'](Trip是属性名称,不是包含Stops的父对象)

内容的提问来源于stack exchange,提问作者Matt C

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 22:12:48