javascript - 附加元素时获取行为?
问题描述
为什么appendChild
正常工作?console.log 显示了一个空的 tr 元素,我认为这是因为 fetch(在 api_search 函数中)是异步的,但是 appendChild 设法用获取的数据填充我的表,所以那里的行有什么不同反对console.log?
let row = document.createElement("tr");
if (ref.record) {
api_search(ref.record.$ref, {
fields: ['titles', 'authors', 'citation_count']
})
.then(data => {
var title = data.titles[0].title
var url = api_to_url(ref.record.$ref)
var authors = data.authors
var citations = data.citation_count
row.innerHTML = inspire_paper_info(title, authors, url, citations)
})
console.log(row)
inspireTable.appendChild(row)
}
解决方案
推荐阅读
- magento - Magento 2.3 上的登录模块
- python - Matplotlib 动画未按预期绘制线条
- azure-active-directory - 使用服务主体的 Power BI REST API - 错误 401 未经授权
- multithreading - 如何在@threads 中“锁定”变量?
- pandas - 熊猫检查数据框中的每个值并在条件满足时替换它
- flutter - Flutter ExpansionTile 扩展按钮位置
- airflow - 无法使用 PIP 安装airflow-pentaho-plugin python 包
- ngx-graph - 有没有办法在 ngx-graph 中的节点上方显示边缘?
- java - Java 正则表达式检查
- vue.js - 如何使用 axio 调用的响应来构建另一个请求