简体   繁体   English

数据不会显示在表格中,但会显示在 console.log 中

[英]Data won't show up in table but does in console.log

My data does show up in the console.log but not actually into the table, what am I doing wrong here?我的数据确实显示在 console.log 中,但实际上并没有显示在表中,我在这里做错了什么?

$.getJSON("http://localhost:3000/api/metatrader", function(data){ console.log(data.result)

var table = document.getElementById('historyTable')

for (var i = 0; i < data.length; i++){
  var row = `<tr>
                <td>${data.result[i].order}</td>
                <td>${data.result[i].symbol}</td>
                <td>${data.result[i].size}</td>
                <td>${data.result[i].profit}</td>
                <td>${data.result[i].tp}</td>
                <td>${data.result[i].sl}</td>
            </tr>`
  table.innerHTML += row

}

});

You want to iterate over data.result, so try this instead:你想迭代 data.result,所以试试这个:

for (var i = 0; i < data.result.length; i++){

And to insert rows, follow the instruction from this exampe: https://www.w3schools.com/jsref/met_table_insertrow.asp要插入行,请按照以下示例中的说明进行操作: https://www.w3schools.com/jsref/met_table_insertrow.asp

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

相关问题 console.log不会在Facebook的萤火虫中显示 - console.log won't show in firebug on facebook console.log() 不显示实际值 - console.log() does not show actual value 为什么console.log无法显示我的整个javascript多维数组? - Why won't console.log show my whole javascript multidimensional array? 使用react和Express.js获取API响应不会通过console.log显示任何结果 - Fetch API response with react and Express.js won't show any result with console.log Node.js 5.5.0 console.log将不会记录 - Node.js 5.5.0 console.log won't log React&ASP.NET MVC 5服务器端渲染console.log(&#39;text&#39;)未显示 - React & ASP.NET MVC 5 server side rendering console.log('text') does not show up Javascript:console.log(arr.length)表示长度为n,console.log(arr)表示长度为n-1。 第二种情况不会显示最后一个元素 - Javascript: console.log(arr.length) says length is n, console.log(arr) says length is n-1. Second case won't show last element 不想在console.log中显示特定的键及其值 - Don't want a particular key and its value to show up in console.log 如果方法抛出异常,Node.js:console.log消息不显示...为什么? - Node.js: console.log message doesn't show up if method throws exception… why? 主干木偶console.log将不会输出 - Backbone Marionette console.log won't output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM