如何使用 P5.js 添加表格行? [英] How to add a table row with P5.js?

查看:73
本文介绍了如何使用 P5.js 添加表格行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<table class="table">
   <tbody id="user_table" class="user_table">

   </tbody>
</table>

我正在从 fire base 加载我的数据并想用 P5 创建一个表.这是我试过的.

I am loading my data from fire base and want to create a table with P5. This is what I have tried.

for (var i = 0; i < keys.length; i++) {
        var tr = createElement("tr");
            tr.parent("user_table");
            tr.class("success");
        var td_1 = createElement("td");
            td_1.html(player_data[i][0]);
            td_1.class('myclass-td');
            td_1.parent("success");
        var td_2 = createElement("td");
            td_2.html(player_data[i][1]);
            td_2.class('myclass-td');
            td_2.parent("success");
    }

我以这种方式添加了列表,但向表中添加一行似乎不起作用.

I have added lists this way, but adding a row to a table doesn't seem to work out.

推荐答案

我最终使用纯 JavaScript 完成了这项工作.

I ended up doing it with pure JavaScript.

// Displaying data
    var table = document.getElementById("user_table");
    for (var i = 0; i < keys.length; i++) {
        var row = table.insertRow(i);
        var cell1 = row.insertCell(0);
        var cell2 = row.insertCell(1);
        cell2.innerHTML = player_data[i][0];
        cell3.innerHTML = player_data[i][1];
    }

这篇关于如何使用 P5.js 添加表格行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆