简体   繁体   English

如何解构具有特殊字符并使用 object 别名的嵌套 object

[英]How to destructure a nested object with special character and using object alias

I have been wondering if there is a way I can destructure this object in the snippet.我一直想知道是否有一种方法可以在片段中解构这个 object。

在此处输入图像描述

Here is what I have tried but it seems not working...这是我尝试过的,但似乎不起作用...

const {
    _links: {
      self: [{ href: mainMedia }],
    },
    _links: { "wp:attachment": attachmentMedia:{[{href:attachment}]} },
    _links: { "wp:featuredmedia": featuredMedia:{[{href:attachment}] } }
  } = data;

The attachmentMedia and featuredMedia are my alias and I am interested in the link each array. attachmentMediafeaturedMedia是我的别名,我对每个数组的链接感兴趣。

MDN docs seems not to have this MDN 文档似乎没有这个

const [{ href: mainMedia }] = data._links["self"];

const attachmentMedia = data._links["wp:attachment"]
  .map(({ href: attachment }) => ({ attachment }));

const featuredMedia = data._links["wp:featuredmedia"]
  .map(({ href: attachment }) => ({ attachment }));

Is this your expectation?这是你的期望吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM