【发布时间】:2020-05-26 17:58:07
【问题描述】:
有人知道在读取 Google 自定义搜索结果对象时使用的语法吗?
这是来自https://developers.google.com/custom-search/docs/element 的结果对象的 JSDoc 表示法:
{
content: string,
contentNoFormatting: string,
contextUrl: string, // For image search results only
fileFormat: string,
image: { // For image search reseults only
height: number,
url: string,
width: number,
},
perResultLabels: !Array<{
anchor: string,
label: string,
labelWithOp: string,
}>,
richSnippet: !Array<!Object>, // For web search results only
thumbnailImage: {
height: number,
url: string,
width: number,
},
title: string,
titleNoFormatting: string,
url: string,
visibleUrl: string,
}
我需要访问“url”(thumbnailimage.url),但不确定引用它的语法。
这里是我需要使用它的地方。见下方评论
here is where I need to use it. See comment below
const makeResultParts = (result) => {
const anchor = document.createElement('a');
anchor.href = result['thumbnailImage'] // <<---this needs to be the thumbnailImage.url but that syntax does not work
anchor.target = '_blank';
anchor.classList.add('gs_title');
anchor.appendChild(document.createTextNode(result['visibleUrl']));
const span = document.createElement('span');
span.innerHTML = ' ' + result['title'];
return [anchor, span];
};
【问题讨论】:
标签: javascript jsdoc google-custom-search