最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

Underscorejs洗牌与EJS

IT培训 admin 6浏览 0评论

Underscorejs洗牌与EJS

使用

是否有可能使用_.shuffle(list)与EJS?

我得到_没有定义。

<script type=".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]); %>
回答如下:

我会想象的过程是相似的,但是这是我做我的EJS文件模板使用moment

# routes.js

const moment = require('moment');


app.get('/fixtures', (req, res) => {
  const file = await readFile('./views/partials/fixtures.ejs');
  const fixtureTemplate = ejspile(file, { client: true });
  const html = fixtureTemplate({ moment });
  res.send({ html });
});

在我examples.ejs文件,我可以再使用瞬间像这样

<%=  moment.utc(fixture.kick_off).local().format('HH:mm') %>

希望你可以按照使用underscore相同的过程

Underscorejs洗牌与EJS

使用

是否有可能使用_.shuffle(list)与EJS?

我得到_没有定义。

<script type=".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]); %>
回答如下:

我会想象的过程是相似的,但是这是我做我的EJS文件模板使用moment

# routes.js

const moment = require('moment');


app.get('/fixtures', (req, res) => {
  const file = await readFile('./views/partials/fixtures.ejs');
  const fixtureTemplate = ejspile(file, { client: true });
  const html = fixtureTemplate({ moment });
  res.send({ html });
});

在我examples.ejs文件,我可以再使用瞬间像这样

<%=  moment.utc(fixture.kick_off).local().format('HH:mm') %>

希望你可以按照使用underscore相同的过程

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论