Javascript 如何在模板引擎中使用getter方法?

Javascript 如何在模板引擎中使用getter方法?,javascript,node.js,pug,Javascript,Node.js,Pug,我正在用node js做一个爱好项目,pug js是我的模板引擎,现在我需要在pug中使用sequelize get方法, 当我包含相应的代码时,它在那里运行,我在控制台中获得所需的输出,但在前端无法获得它 block content main h1.text_center Task Assigned for #{task_added[0].userName} if task_added table(border=1)

我正在用node js做一个爱好项目,pug js是我的模板引擎,现在我需要在pug中使用sequelize get方法, 当我包含相应的代码时,它在那里运行,我在控制台中获得所需的输出,但在前端无法获得它


block content
    main
        h1.text_center Task Assigned for #{task_added[0].userName}
        if task_added
            table(border=1)
                tr
                    th tasks
                    th project
                    th start-date
                    th status
                    th action
                each task in task_added
                    tr
                        td #{task.task}
                #this is where i am having issue
                        td= task.getProject().then(project =>{projectName = project.project;console.log(projectName);})
                        td #{task.start_date}
                        if task.status == 0
                            td not-started
                        else if task.status == 1
                            td started on #{task.start_date}
                        else
                            td finished on #{task.completed_date}
                        if task.status == 0
                            td
                                form(method='POST', action=('/admin/start'))
                                    input(type='hidden' name='userId' value=(task.userID))
                                    input(type='hidden' name='taskId' value=(task.id))
                                    button(type="submit") start
                        else if task.status == 1
                            td
                                form(method='POST', action=('/admin/complete'))
                                    input(type='hidden' name='userId' value=(task.userID))
                                    input(type='hidden' name='taskId' value=(task.id))
                                    button(type="submit") complete
                        else
                            td Change-Status
                        td
                            a(href='/admin/details/' + task.id) details

我认为不能直接调用pug模板中的服务器端函数

通常你把函数传递给它。express示例

res.render('pug-filename', {
  getProjectName: function () {
    return task.getProject().then(project => { projectName = project.project; })
  }
});
在你的哈巴狗档案中:

td #{getProjectName()}

我认为不能直接调用pug模板中的服务器端函数

通常你把函数传递给它。express示例

res.render('pug-filename', {
  getProjectName: function () {
    return task.getProject().then(project => { projectName = project.project; })
  }
});
在你的哈巴狗档案中:

td #{getProjectName()}

我们可以把arguments传递给它吗?我认为我们不能在pug模板引擎中生成异步函数,我们可以把arguments传递给它吗?我认为我们不能在pug模板引擎中生成异步函数,这不是getter方法。这是一个promise方法,sequelize数据库调用是异步的。在将数据传递到模板引擎之前执行此操作!这不是一个getter方法。这是一个promise方法,sequelize数据库调用是异步的。在将数据传递到模板引擎之前执行此操作!