Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.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/1/ssh/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
Node.js 模板引擎将我的代码设置到错误的位置。什么';这是个错误吗?_Node.js_Express_Template Engine - Fatal编程技术网

Node.js 模板引擎将我的代码设置到错误的位置。什么';这是个错误吗?

Node.js 模板引擎将我的代码设置到错误的位置。什么';这是个错误吗?,node.js,express,template-engine,Node.js,Express,Template Engine,模板引擎将我的代码设置到表格标题的错误位置。它成功地设置了简单的字符串对象,但它将我的表行设置为绝对错误 app.js app.get("/", function(req,res) { const collection = req.app.locals.collection; collection.find({}).toArray(function(err, messages) { participants = Analise(messages, collec

模板引擎将我的代码设置到表格标题的错误位置。它成功地设置了简单的字符串对象,但它将我的表行设置为绝对错误

app.js

app.get("/", function(req,res) {

    const collection = req.app.locals.collection;
    collection.find({}).toArray(function(err, messages) {

        participants = Analise(messages, collection);
        console.log(participants);

        if(err) return console.log(colors.red(err));

        res.render("main.hbs", {
            title: "tg:analitycs",
            captition: "Таблица пользователей",
            cap: "",
            table: genTable(participants),
        });
    });
});

function genTable(p) {
    let rows = '';
    for (let i=0; i<p.length; i++) {

        rows += "<tr><th>"+p[i].id+"</th><th>"+p[i].first_name+"</th><th>"+p[i].last_name+"</th><th>"+p[i].username+"</th><th>"+p[i].total+"</th><th>"+p[i].type_text+"</th><th>"+p[i].type_image+"</th></tr>";
    }
    return rows;
}
app.get(“/”,函数(req,res){
const collection=req.app.locals.collection;
collection.find({}).toArray(函数(err,消息){
参与者=分析(信息、收集);
console.log(参与者);
if(err)返回console.log(colors.red(err));
res.render(“main.hbs”{
标题:“tg:分析药”,
标题:“аааааааазааааааа,
第1章:,
表:genTable(参与者),
});
});
});
函数genTable(p){
让行=“”;
for(设i=0;i头}
  • {{captition}}
  • {{cap}}
用户id 名字 姓 用户名 邮件总数 文本 图像 {{table}} {{>页脚}
通过链接输出屏幕截图:

哪里是错误,还是错误?谢谢

附言:呈现桌子的最佳方式是什么?我想:

  • 按列排序
  • 渲染所有数据的一部分

我不想添加行、删除行或更改行。仅输出表。

首先,将变量中的所有收集数据发送到html页面,如下所示:

    res.render("main.hbs", {
        title: "tg:analitycs",
        captition: "Таблица пользователей",
        cap: "",
        user_data: participants
    }); 
那么这个表应该是这样的:

 <table>
    <thead>
        <tr>
            <th>user_id</th>
            <th>First name</th>
            <th>Last name</th>
            <th>Username</th>
            <th>total messages</th>
            <th>text</th>
            <th>images</th>
        </tr>
    </thead>

    <tbody>
        <tr>
        {% for data in user_data %}
            <td>{{data.id}}</td>
            <td>{{data.first_name}}</td>
            ...
            ...

        </tr>
        {% endfor %}
    </tbody>
 </table>

用户id
名字
姓
用户名
邮件总数
文本
图像
{%用于用户_data%中的数据}
{{data.id}
{{data.first{u name}
...
...
{%endfor%}

首先,将变量中收集的所有数据发送到html页面,如下所示:

    res.render("main.hbs", {
        title: "tg:analitycs",
        captition: "Таблица пользователей",
        cap: "",
        user_data: participants
    }); 
那么这个表应该是这样的:

 <table>
    <thead>
        <tr>
            <th>user_id</th>
            <th>First name</th>
            <th>Last name</th>
            <th>Username</th>
            <th>total messages</th>
            <th>text</th>
            <th>images</th>
        </tr>
    </thead>

    <tbody>
        <tr>
        {% for data in user_data %}
            <td>{{data.id}}</td>
            <td>{{data.first_name}}</td>
            ...
            ...

        </tr>
        {% endfor %}
    </tbody>
 </table>

用户id
名字
姓
用户名
邮件总数
文本
图像
{%用于用户_data%中的数据}
{{data.id}
{{data.first{u name}
...
...
{%endfor%}