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

如何从resolveProductNodes返回的已兑现Promise中提取mObjectUUID?

提取Promise结果中的mObjectUUID字段

你可以在then()的回调函数里直接处理返回的数组,因为then()的参数就是Promise兑现后的[[PromiseResult]]值。

基础实现

如果确定数组里只有一个对象,直接通过索引访问后提取字段:

resolveProductNodes().then(resultArray => {
  // 数组的第一个元素就是目标对象
  const targetObj = resultArray[0];
  // 提取mObjectUUID字段
  const mObjectUUID = targetObj.mObjectUUID;
  // 后续可以使用这个值做其他操作
  console.log(mObjectUUID);
});

健壮性处理(考虑数组为空的情况)

如果不确定数组是否有元素,建议先做判断避免报错:

resolveProductNodes().then(resultArray => {
  if (resultArray.length > 0) {
    const mObjectUUID = resultArray[0].mObjectUUID;
    console.log(mObjectUUID);
  } else {
    console.log('数组中没有找到目标对象');
  }
});

使用async/await写法(更简洁)

如果你习惯异步函数的写法,也可以用async/await替代then():

async function getObjectUUID() {
  const resultArray = await resolveProductNodes();
  if (resultArray.length > 0) {
    const mObjectUUID = resultArray[0].mObjectUUID;
    console.log(mObjectUUID);
    return mObjectUUID;
  }
}

// 调用函数
getObjectUUID();

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 03:21:30