问题
通过一些在线示例,您可以使用这样的语法
<%- include hello-world %>
Run Code Online (Sandbox Code Playgroud)
或者甚至你可以使用
<%- include('hello-world'); %>
Run Code Online (Sandbox Code Playgroud)
您可能会收到包含缺少文件名的错误
Exception occurred: Error: `include` requires the 'filename' option.
Run Code Online (Sandbox Code Playgroud)
问:如果我的语法正确,问题出在哪里?
如何在 ejs 中将对象作为参数发送。当我尝试在测试函数的参数中发送对象时,它会打印 undefined 。
</tr>
<% userlist.forEach(function(usr){ %>
<tr>
<td><input readonly type="text" value="<%= usr.name %>"></td>
<td><input readonly type="text" value="<%= usr.email %>"></td>
<td style="cursor:pointer">
<i title="edit data" style="padding-right:18px" class="fa fa-pencil"></i>
<i title="delete" ng-click='test(<%= usr %>)' class="fa fa-trash"></i></td>
</tr>
<% }) %>
<% } %>
Run Code Online (Sandbox Code Playgroud) 我尝试使用 d3-node 在服务器端制作图表,并尝试使用以下代码将新图表渲染到 ejs: <%= svgChart %> 当我使用浏览器查看它时,它只显示 svg 标签内容,如下所示:
<svg xmlns="http://www.w3.org/2000/svg" width="960" height="400"><defs> <style type="text/css"><![CDATA[ .axis{font: 10px sans-serif;} .axis path,.axis line{fill: none;stroke: #000;shape-rendering: crispEdges;} .x.axis path{display: none;} ]]></style></defs><g transform="translate(40,20)"><path d="M20,32.4L20.430000000000003,32.4L20.86,32.4L21.290000000000003,32.4L21.720000000000002,32.4L22.150000000000002,32.4L22.580000000000002,32.4L23.01,32.4L23.44,32.4L23.87,32.4L24.299999999999997,32.4L24.73,32.4L25.16,32.4L25.590000000000003,32.4L26.02,32.4L26.450000000000003,32.4L26.88,32.4L27.310000000000002,32.4L27.740000000000002,32.4L28.17,32.4L28.6,32.4L29.03,32.4L29.46,32.4L29.89,32.4L30.32,32.4L30.75,32.4L31.18,32.4L31.61,32.4L32.04,32.4L32.47,32.4L32.9,32.4L33.33,32.4L33.76,32.4L34.190000000000005,32.4L34.620000000000005,32.4L35.050000000000004,32.4L35.480000000000004,32.4L35.910000000000004,32.4L36.34,32.4L36.77,32.4L37.2,32.4L37.63,32.4L38.06,32.4L38.489999999999995,32.4L38.92,32.4L39.35,32.4L39.78,32.4L40.21,32.4L40.64,32.4L41...............................
Run Code Online (Sandbox Code Playgroud)
不显示图表本身。svgChart 包含 svg 标签的字符串。如果我将 svgChart 内容(字符串)直接复制到 ejs,它将完美显示图表。
加载页面时,ejs 似乎无法渲染标签内容。它认为 svgChart 作为纯字符串。
我的问题:如何使 ejs 将 svgChart 识别为 svg 标签,以便它可以显示 svg 图表而不是标签的文本?
我只是想问一下如何在html输入字段中阻止<、>、"、/等特殊字符?
如何将 $ 添加到以下输入:
<td class="td10"><input type='text' class='form-control' id="boqRate" name="boq[boqRate]"></td>
Run Code Online (Sandbox Code Playgroud) 我最近正在学习构建一个 hexo 主题,但我对__()功能感到困惑。我在 hexo doc 中没有找到答案。我不知道这是内置的还是什么?
此代码来自主题米诺斯:
<span class="column is-narrow">
<% let words = word_count(post._content); %>
<% let time = duration((words / 150.0) * 60, 'seconds') %>
<%= `${ time.humanize() } ${ __('article.read')} (${ __('article.about') } ${ words } ${ __('article.words') })` %>
</span>
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我吗?
我在我的项目中使用express-ejs-layout。我的项目有路由。我想为不同的 res 查询使用不同的布局。例如,如果查询是:www.xxx.com/a,则使用 LayoutA.ejs,如果查询是:www.xxx.com/b,则使用 LayoutB.ejs。我的 index.js 部分代码是:
...
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, '/app_server/views'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(ejsLayout);
app.use('/public', express.static(path.join(__dirname, 'public')));
require('./app_server/routes/routeManager')(app);
...
Run Code Online (Sandbox Code Playgroud)
我怎样才能?
提交表单后,我想呈现相同的页面,但在表单上方显示“消息发送成功”消息。使用此代码,我收到“引用错误,未定义 msg”,我觉得这很奇怪,因为当我使用相同的代码但在 GET 请求中它运行良好。GET 和 POST 请求之间是否有不同的技术?
const express = require('express');
const app = express();
app.set('view engine', 'ejs');
app.get('/contact', (req, res) => {
res.render('contact');
});
app.post('/send', (req, res) => {
res.render('contact', {msg: 'Message sent successfully!'});
});Run Code Online (Sandbox Code Playgroud)
<section class="section-b">
<div>
<p><%= msg %></p>
<form action="send" id="contact-form" method="POST">
<input type="text" name="name" placeholder="Name">
<input type="email" name="emailContact" placeholder="E-mail"><br>
<textarea name="message" id="message" rows="10" placeholder="Your message here..."></textarea><br>
<button type="submit">Submit</button>
</form>
</div>
</section>Run Code Online (Sandbox Code Playgroud)
我正在使用Express、EJS和 MongoDB 开发博客应用程序(单击链接以查看GitHub 存储库)。
我为帖子制作了一个简单的寻呼机。
在帖子控制器中,我有:
exports.getPosts = async (req, res, next) => {
const posts = await Post.find({}, (err, posts) => {
const perPage = 10;
const currPage = req.query.page ? parseInt(req.query.page) : 1;
const postsCount = posts.length;
const pageCount = Math.ceil(postsCount / perPage);
const pageDecrement = currPage > 1 ? 1 : 0;
const pageIncrement = currPage < pageCount ? 1 : 0;
if (err) {
console.log("Error: ", …Run Code Online (Sandbox Code Playgroud) 我有一个前端带有 EJS 的 Node Express 应用程序。
我有一个带护照的中间件功能,它在所有创建、编辑、删除路由之前运行。
function isLoggedIn(req, res, next) {
if (req.isAuthenticated()) {
if (req.user._id != "12345") {
res.redirect("/error");
}
return next();
}
res.redirect("/error");
}
Run Code Online (Sandbox Code Playgroud)
我能想到的最好的方法是通过 mongo db 中的用户 id 和 req.user._id 检查我的管理员用户是否是尝试访问该路由的用户
有没有更好的方法来处理管理员用户对路由和 html 组件的访问?
ejs ×10
node.js ×8
javascript ×5
express ×4
css ×2
html ×2
angularjs ×1
hexo ×1
jquery ×1
mean ×1
mean-stack ×1
mongodb ×1
passport.js ×1
render ×1
server-side ×1
svg ×1