问题描述
我是node.js,jade和&的新手.表达,所以请忍受我.
I'm new to node.js, jade, & express, so please bear with me.
我有以下文件.
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");
});
过程:
- 用户启动并加载网站.他们看到初始索引页面
- 用户单击表单,该表单触发一个调用剩余部分的操作api getReports
- 该调用将呈现应仅将添加的子项"附加到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页面.该按钮触发对服务器的操作调用.服务器处理数据,然后目标是获取数据并处理要在index.jade页面上显示的模板.
The problem i'm having is that this code is the client side is the index.jade page. 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.
通常,如果没有玉器模板文件,我将只使用javascript并采用幼稚的方式,即让客户端Java代码触发ajax调用,并在响应中使用DOM将html附加到处理后的数据中但是我想利用玉.
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.
任何建议,我们感激不尽,谢谢,D
Any advice Appreciated,Thanks,D
推荐答案
以下是一些可能对您有帮助的指针,
Here are some pointers that might help you,
-
在
res.render("child.jade");
中,不包括玉器文件.jade
的扩展名.只需res.render("child");
即可.
In
res.render("child.jade");
, don't include extension of the jade file,.jade
. Justres.render("child");
will work.
在您的"child.jade"中,阻止附加内容
是错误的,因为没有具有该名称的阻止.如果要在索引页面中渲染某些局部图像,则应在"index.jade"中指定一个块.像这样
In your "child.jade", block append content
is wrong as there is no block with that name. If you want to render some partial in index page then you should specify a block in "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
和"child.jade"到
and "child.jade" to,
extends index
block child
label added child
这篇关于带有jade,express和node.js的渲染模板的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!