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

如何获取对象指定属性?调用data.entry.properties['pm:taggable']返回undefined

获取对象属性中pm:taggable的ID数组问题解决

问题描述

尝试获取data.entry.properties中的pm:taggable对应ID数组时,控制台返回undefined,且报错:properties of undefined (reading 'cm:taggable')。此前执行console.log(data.entry.properties)能看到包含pm:title和pm:taggable的属性结构。

已知数据结构:

data: {
    entry: {
      isFile: true,
      createdByUser: [Object],
      content: [Object],
      aspectNames: [Array],
      isFolder: false,
      modifiedByUser: [Object],
      name: 'Cine',
      properties: [Object]
    }
  }

properties具体结构:

"properties": {
            "pm:title": "Scary movie",
            "pm:taggable": [
                "a112a22463563-9c56-428f-a4ac-a2341as2a",
                "2545ds467-62e5-448d-a062-34sf466dfs",
                "a3af33-2b8d-40c3-98c3-3awfsa356a"
            ],
            "cm:description": "Description"
        }

解决步骤

  • 检查拼写错误:报错信息里提到的是cm:taggable,但你要访问的是pm:taggable,确认代码中没有把属性名写错。
  • 确认数据是否同步加载:控制台显示的[Object]可能是异步填充的,当前代码执行时properties还未被赋值。可以用JSON.stringify打印完整同步数据:
    console.log(JSON.stringify(data.entry.properties));
    
    如果是异步获取的数据(比如接口请求),要确保在数据返回后再执行属性访问逻辑,比如用async/await或者回调函数包裹代码。
  • 安全访问属性:使用可选链操作符避免因中间属性未定义而报错,同时获取目标数组:
    console.log(data?.entry?.properties?.["pm:taggable"]);
    
  • 分步调试:先把properties存到变量中,再访问目标属性,方便排查问题:
    const properties = data.entry.properties;
    console.log(properties);
    console.log(properties["pm:taggable"]);
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 02:15:38