arrays - Underscorejs 使用 EJS 随机播放
问题描述
使用https://underscorejs.org/#shuffle
是否可以_.shuffle(list)
与 EJS 一起使用?
我得到 _ 没有定义。
<script type="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"></script>
<% var breakfastFoods = [] %>
<% var breakfastFoodsInfo = [] %>
<% for (var food of allDBFoods) { %>
<% if (food.breakfast == true ){ %>
<% breakfastFoods.push(food.name) %>
<% breakfastFoodsInfo.push(food.info) %>
<% } %>
<% } %>
<% _.shuffle([breakfastFoods]); %>
解决方案
我想这个过程是相似的,但这就是我moment
在我的 EJS 文件模板中使用的方法
# routes.js
const moment = require('moment');
app.get('/fixtures', (req, res) => {
const file = await readFile('./views/partials/fixtures.ejs');
const fixtureTemplate = ejs.compile(file, { client: true });
const html = fixtureTemplate({ moment });
res.send({ html });
});
在我的examples.ejs
文件中,我可以像这样使用时刻
<%= moment.utc(fixture.kick_off).local().format('HH:mm') %>
希望您可以遵循相同的使用过程underscore
推荐阅读
- java - Android 大小分析器插件错误 - IDE 致命错误(“AnalyzeMenu”未注册)
- r - 在 R 中显示包含数字范围(0-9 之间)的行数
- javascript - 如何使用变量每秒更改类名?
- python - 创建一个介于 -1 和 1 之间的随机 numpy 数组,所有元素的总和为零
- node.js - Nodejs 使用临时凭证错误连接到 Redshift
- ansible - ansible:以不同的用户身份运行角色
- python - 开发和测试 Python 代码以连接本地机器上的 kafka 流
- python-3.x - 展开多维 Numpy 数组
- java - 记录每种方法与使用 Aspect 记录?
- flutter - 带有 TypeError 异常的 Dart 结果