- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我当前正在 JavaScript 中循环一个对象,并成功从 _source
级别获取了我需要的内容。我现在的问题是 _source
内的 color
下还有另一个数组。
目前,console.log(searchResult);
给了我这个对象:
1
_source
color
1
color_type
type
name
id
我可以访问 type
和 color
,因为它们位于 _source
级别,但我需要访问 color_type
是 color
中另一个数组的一部分,它显然需要是我最初索引元素中包含的信息。
我需要在此处创建一个新循环来访问颜色
信息吗?
let searchResult = response.hits.hits;
console.log(searchResult);
for(let i = 0; i < searchResult.length; i++) {
//This line displays the name.id properly
document.getElementById("name").value = searchResult[i]._source.type.name.id;
//this line gives undefined
document.getElementById("color").value = searchResult[i]._source.color[i].color_type;
})
}
最佳答案
由于您只对第二个元素(索引 1)感兴趣,因此这应该可以解决问题:
document.getElementById("color").value = searchResult[i]._source.color[1].color_type;
关于javascript - 在对象的现有循环内循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52082384/
我在这里打破了头,请帮忙。 我正在抓取一个网站。 .MyElement 容器包含我尝试获取的 gif 或 jpg 源 url。 我在我的 node.js 应用程序中使用基于 Cheerio 的 .ea
尝试使用 dictionaryWithObjectsAndKeys 向字典添加值,我想使用 for 循环添加对象,但我找不到正确的出路,请帮忙,使用 for 循环仅显示最后一个值,其他值不出现.看起来
我在 for 循环中有一个 lambda,lambda 中有循环变量参数。当我运行它时,我希望输出数字 0-9。但由于它是一个 lambda,x 不会立即得到评估。 for( int x =
我正在尝试在 C# 中的循环内插入一条数据库记录。 当我像这样对值进行硬编码时它会起作用: string query3 = "INSERT INTO furniture (room_id,me
仍在处理我在 Haskell 中的 SHA1 实现。我现在有了一个可行的实现,这是内部循环: iterateBlock' :: Int -> [Word32] -> Word32 -> Word32
我试图在具有相同类名的 div 内循环。这是为了获得正确的查询字符串,我想稍后将其用于 getJSON 。问题是我无法从 div 中获取各种参数... 这是创建 div 的代码(这个工作正常,我用 C
我想要实现的是 Qt Widget 循环。 简单的例子: UI_dialog 是一个 QDialog,接受后它将打开 UI_mainwindow,它是一个 QMainWindow。 UI_mainwi
谁能解释一下这个算法的时间复杂度是多少? for (i = 1; i = n + n/2 + n/3 ... n/n但是是 < n + 1 + n/2 + 1 + n/3 + 1 + n/4 + 1.
这个问题已经有答案了: JavaScript setTimeOut doesn't seem to work like I expect (1 个回答) 已关闭 5 年前。 为了最佳实践,JS 的相对
我在 Multimap 中创建了 Integer 和 Multimap,并且尝试循环获取键和值。然而,对于 Multimap,它以数组形式返回,我无法删除该数组并仅获取 int。 这是我的代码 pub
我想遍历我所有的 delicious.com 书签并在它们周围添加一个链接... 这是我的测试站点: http://dev.thomasveit.com/json.html $(document).r
我正在尝试执行一些逻辑,它将编辑 minheap.heapList 的长度。我对 Promises 还很陌生,所以我不知道如何解决这个问题。在 while 循环 中,我还将调用一些 async 函数。
我是 VBA 新手,刚开始学习循环。 这是我的代码: sub worksheet_change(byval target as range) application.screenupdating =
我在 R 中运行以下脚本。 如果我使用 %do% 而不是 %dopar% 脚本工作正常。但是,如果在外循环中我使用 %dopar% 循环将永远运行而不会引发任何错误(内存使用量不断增加,直到内存不足)
我有一个 case 语句,如 1) 2) 3) ... 如下,其中 1) 格式 case 有多个 if else 条件。我想在无效条件下重复特定情况。当用户首先选择 1 时,它会询问果汁的名称。接下来
我正在尝试将 html block 传递给电子邮件服务 Nodemailer JS 函数(我使用的是 Node.JS)。我有一个items需要在电子邮件中发送的数组: items = [ { n
我在 page.evaluate 方法中有一个循环。该循环迭代一个查询选择器,该选择器从页面中文本元素的多个实例捕获innerText。 我收到错误评估失败:无法读取“innerText”的属性 我尝
我无法理解如何为下面的资源创建循环。我需要基于嵌套在“维度”块中的变量“实例”创建多个资源。根据我阅读一些文档后的理解,我应该使用 for_each 参数,但是我似乎无法弄清楚。 resource "
我是一名优秀的程序员,十分优秀!