简体   繁体   English

带有jade,express和node.js的渲染模板的问题

[英]Issue with Rendering templates with jade, express, and node.js

I'm new to node.js, jade, & express, so please bear with me. 我是Node.js,Jade和Express的新手,所以请多多包涵。

I have the following files. 我有以下文件。

layout.jade layout.jade

index.jade index.jade

extends layout
block content
    label initial layout
    form(action="/getReports", method="GET", enctype="multipart/form-data")
        input(type='submit', value='Generate Report')

child.jade child.jade

extends index
block append content
    label added child

server.js server.js

app.get('/getReports', function(res, req)
{
    res.render("child.jade");
});

Process: 处理:

  1. User comes on and loads the site. 用户启动并加载网站。 They see the initial index page 他们看到初始索引页面
  2. User clicks on the form which triggers an action that calls the Rest Api getReports 用户单击表单,该表单触发一个调用Rest Api getReports的操作
  3. The call will render the child template that should just append "added child" to the content part of index.jade. 该调用将呈现子模板,该子模板应仅将“添加的子”附加到index.jade的内容部分。

However, I'm not seeing this. 但是,我没有看到。 I guess I'm trying to understand the best approach to append a partial template that is rendered to the original index.jade page. 我想我想了解最好的方法,以将呈现给原始index.jade页面的部分模板附加到模板中。

The problem i'm having is that this code is the client side is the index.jade page. 我遇到的问题是此代码是客户端是index.jade页面。 The button triggers an action call to the server. 该按钮触发对服务器的操作调用。 The server processes data, then the goal is to take the data and process a template that it was to display on the index.jade page. 服务器处理数据,然后目标是获取数据并处理要在index.jade页面上显示的模板。

Normally, without the jade template files, I would just use javascript and to the naive way which would be just have the client side java code trigger the ajax call and in the response use the DOM to append the html with the processed data but I wanted to take advantage of jade. 通常,如果没有jade模板文件,我将只使用javascript并采取一种幼稚的方式,即让客户端Java代码触发ajax调用,并在响应中使用DOM将html附加处理后的数据,但是我想要利用玉。

Any advice Appreciated, Thanks, D 任何建议表示赞赏,谢谢,D

Here are some pointers that might help you, 以下是一些可能对您有帮助的提示,

  1. In res.render("child.jade"); res.render("child.jade"); , don't include extension of the jade file, .jade . ,不包括jade文件.jade扩展名。 Just res.render("child"); 只是res.render("child"); will work. 将工作。

  2. In your "child.jade", block append content is wrong as there is no block with that name. 在您的“ child.jade”中, block append content是错误的,因为没有具有该名称的块。 If you want to render some partial in index page then you should specify a block in "index.jade". 如果要在索引页面中呈现部分片段,则应在“ index.jade”中指定一个块。 Make it like, 像这样

     extends layout block content label initial layout form(action="/getReports", method="GET", enctype="multipart/form-data") input(type='submit', value='Generate Report') block child 

    and "child.jade" to, 和“ child.jade”

     extends index block child label added child 

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM