Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将对象内部的对象加载到html表中_Javascript_Node.js_Object_Filewalker - Fatal编程技术网

Javascript 将对象内部的对象加载到html表中

Javascript 将对象内部的对象加载到html表中,javascript,node.js,object,filewalker,Javascript,Node.js,Object,Filewalker,因此,我试图在node.js和socket.io中创建一个文件管理器,以便每次walker模块检测到一个文件或文件夹时,它都会向客户端发送一个事件,使用这个大函数将其放入表中 socket.on('loadItem', function(type, name, dateCreated, size, itemPath, parentPath, fileExtension){ if (type == 'dir'){ var itemPathID = i

因此,我试图在node.js和socket.io中创建一个文件管理器,以便每次walker模块检测到一个文件或文件夹时,它都会向客户端发送一个事件,使用这个大函数将其放入表中

    socket.on('loadItem', function(type, name, dateCreated, size, itemPath, parentPath, fileExtension){
        if (type == 'dir'){
            var itemPathID = itemPath.split(' ').join('-');
            var parentPathID = parentPath.split(' ').join('-');
            console.log('parent-path ' + parentPathID)
            document.getElementById('main-table').innerHTML += '<tr><td><i class="fas fa-folder folder"></i></td><td  class="pointer"  onclick="openChildrenContainer(\'' + itemPathID+ '/\')">' + name+ '</td><td>' + dateCreated + '</td><td>' + size + ' bytes</td> </tr>'
            document.getElementById('main-content-div').innerHTML += '<div id="'+itemPathID+'" class="folder-children-container hidden"></div>'
            document.getElementById(itemPathID).innerHTML += table
        }
        if(type == "file"){
            if(fileExtension == 'js'){
            var parentPathID = parentPath.split(' ').join('-');
            console.log(parentPathID)
            document.getElementById('main-table').innerHTML += '<tr><td><i class="fab fa-js-square js-file"></i></td><td><a class="pointer" onclick="openEditor(\'' + itemPath+ '\')">' + name + '</a></td><td>' + dateCreated + '</td><td>' + size + ' bytes</td></tr>'

        }else if(fileExtension == "txt"){
            var parentPathID = parentPath.split(' ').join('-');
            console.log(parentPathID)
            document.getElementById('main-table').innerHTML += '<tr><td><i class="fas fa-file-alt txt-file"></i></td><td><a class="pointer" onclick="openEditor(\'' + itemPath+ '\')">' + name + '</a></td><td>' + dateCreated + '</td><td>' + size + ' bytes</td></tr>'
        }else if(fileExtension == "css"){
            var parentPathID = parentPath.split(' ').join('-');
            console.log(parentPathID)
            document.getElementById('main-table').innerHTML += '<tr><td><i class="fab fa-css3-alt css-file"></i></td><td><a class="pointer" onclick="openEditor(\'' + itemPath+ '\')">' + name + '</a></td><td>' + dateCreated + '</td><td>' + size + ' bytes</td></tr>'
            }
            else{
                var parentPathID = parentPath.split(' ').join('-');
            console.log(parentPathID)
            document.getElementById('main-table').innerHTML += '<tr><td><i class="fa fa-file-text file"></i></td><td><a class="pointer" onclick="openEditor(\'' + itemPath+ '\')">' + name + '</a></td><td>' + dateCreated + '</td><td>' + size + ' bytes</td></tr>'
            }
        }


    })
然后我把它发送到客户页面,但我的问题是,我不知道如何把它放在我的表格里,这不是一件容易的事,我想我没有试过在没有su的情况下使用它

var cols = ['type', 'name', 'date', 'size'];

    for (var i = 0; i < dirItems.item.length; i++) {
    console.log("moo")
$('#main-table').append('<tr></tr>');

for (var j = 0; j < cols.length; j++) {
    $('#main-table tr:last-child').append('<td>' + dirItems[i][cols[j]] + '</td>');
}
}
var cols=['type','name','date','size'];
对于(变量i=0;i

有任何指针吗?

这是您在ES6中为
循环执行
的方法。其思想是将表作为HTML模板,然后将for循环的结果作为
附加到

var A=[
{类型:'恐龙',名称:'Rex',日期:'1月1日-00',大小:'Massible'},
{类型:'dog',名称:'Woof',日期:'2015年1月12日',尺寸:'impressive'},
{类型:'parrot',名称:'Parry',日期:'2018年3月13日',大小:'fistsize'}
];
为了(动物){
$(“#sometable tbody”).append(“”+animal.type+“”+animal.name+“”+animal.date+“”+animal.size+“”);
}
#sometable{
边框:1px纯黑;
}
#可测量的td{
填料:0.2米1米;
}

类型
名称
日期
大小
var cols = ['type', 'name', 'date', 'size'];

    for (var i = 0; i < dirItems.item.length; i++) {
    console.log("moo")
$('#main-table').append('<tr></tr>');

for (var j = 0; j < cols.length; j++) {
    $('#main-table tr:last-child').append('<td>' + dirItems[i][cols[j]] + '</td>');
}
}