Tag: ejs

获取喜欢的post的ID – Node.js Express Socket.io

我试图build立一个职位系统,人们可以评论和喜欢。 这就是我现在所做的 <!– posts.ejs –> <% posts.forEach(function(task) { %> <%- include post.ejs %> <% }) %> 当有人喜欢,我使用这样的sockets <!– post.ejs –> <script> var socket = io('localhost:48001'); $('#like').on('click', function(event){ var task = <% task._id %> console.log(task); var liker = { pId: task , usr: user._id, liker: 1 }; socket.emit('like', liker, function(response){ if(response==true){ //console.log("blue"); } }); }); //server […]

每个节点模块中的请求variables? (快速查看帮手)

我正在研究这个项目https://github.com/tanema/express-helpers ,我分叉了固定起来,并增加了新的function。 我想要做的,而不是必须使用form_tag_end()甚至end_tag('标记名')我只想使用一个end()方法。 为了这个工作,我需要某种堆栈实现,当一个开始标签被发送到堆栈等。 我不能只在名为tagStack的模块中创build一个variables,只是使用它,因为它会创build一个竞争条件,在这个条件下两个请求同时使用模块,并且堆栈顺序变得混乱。 我在想如果有一些方法来访问请求variables,我只是把它存储在那,并删除variables如果是空的,但我不知道如何做到这一点。 有什么build议么?

在JavaScript中validation模板variables

使用模板引擎进行validation时,是否有最佳实践? 我目前正在用node.js和couchdbbuild立一个站点,而且我正在用ejs作为框架和模板引擎。 我可能最终得到的是[Object object],或者是我的HTML中未定义的拼写。 我可以尝试在沙发上使用validate_doc_update函数进行validation,或者在渲染到模板之前,或者在我的路由函数中的节点中,或者在ejs模板中进行validation。 我应该做哪一个或所有这些?

什么是中间JavaScript的静态caching

我是Node.js和EJS的新手。 “中级JavaScript的静态caching”被称为EJS的一个特性。任何人都可以解释它的真正含义。 问候,Kar

将variables添加到连接资产

我试图从我的app.js文件中添加一些variables到由connect-assets编译的文件中。 我有一个名为file.ejs的文件 <%- js('code.js') %> <input type="text" value="Doe"> 在app.js我有: app.locals.url = 'http://123.123.123.123' 在code.js我想根据系统添加一些生产/开发variables( <%- url %> )。 当我尝试这样做时,添加的variables被拒绝,因为connect-assets正在将它们编译为标记。 将variables传入code.js的正确方法是什么?

在ejs页面中未定义relativeTime()实用程序

使用GeddyJS我已经创build了一个Web应用程序。 我有一个date时间表,我想成为相对的(“5分钟以来…”)。 然而,当我在我的页面中使用它时,GeddyJS文档中的function不可用。 它说 C:\Users\Chris\AppData\Roaming\npm\node_modules\geddy\lib\template\engines\ejs.js:74 throw err; ^ TypeError: ejs:28 26| <td><%= people[i].location %></td> 27| <td><%= people[i].recorder %></td> >> 28| <td><%= geddy.relativeTime(new Date(people[i].time)) %></td> 29| <td><%= people[i].direction %></td> 30| <td><%= people[i].transportation %></td> 31| <td>(<%= people[i].id %>)</td> Object #<Object> has no method 'relativeTime' at Template.handleErr (C:\Users\Chris\AppData\Roaming\npm\node_modules\geddy\lib\template\engines\ejs.js:58:15) at Object.Template.compile.rethrow (C:\Users\Chris\AppData\Roaming\npm\node_modules\geddy\lib\template\engines\ejs.js:90:41) 我应该怎么打电话?

NodeJS Express – 自动呈现页面更新

我有一个后端NodeJS代码,我从一个派生进程收集输出: schild.stdout.on('data', function (data) { var result = data.toString().split("\n"); for(var i = 0; i < result.length; i++) { var n = result[i].split("|"); if(n.length == 4) { var date = n[0]; var category = n[1]; var component = n[2]; var condition = n[3]; response.push({Date : date, Category : category, Component : component, Condition : condition}); } […]

使用Underscore模板定界符的节点项目在EJS视图中发生冲突

有骨干项目使用下划线模板。 在服务器上使用nodejs并使用EJS呈现视图。 下划线模板使用与EJS相同的分隔符,并且由于下划线模板在我的.ejs视图中作为内联脚本标记,所以我收到了错误。 我尝试了下面的解决scheme: app.set('view options', { open: '{{', close: '}}' }); 它似乎仍然试图呈现下划线模板并抛出一个错误: <h2><%= title %></h2> title is not defined 看来在EJS中使用自定义分隔符只是增加了接受而不是改变它们的标签的types。 我也无法find一种方法来吐出原始的HTML,就像你可以在哈姆。

select_tag没有定义

用Express和EJS运行node.js来渲染这里是我的代码: <% var choices = [ {value: '', text: ' ' }, {value: 'HELD', text: 'HELD'}, {value: 'CLEAR', text: 'CLEAR'} ]; var selected = 0; for (var i=0; i<choices.length; i++){ if (manifest.z_customs_status.trim() == choices[i].value){ selected = i; break; } } select_tag('z_customs_status', selected, choices) %> 当代码运行我得到 select_tag is not defined 作为EJS内的错误。 这里logging了select_tag https://code.google.com/p/embeddedjavascript/wiki/ViewHelpers Express是否仍然可以使用EJS进行节点开发?

Express:使用ejs时找不到静态文件

我想我所有的请求被redirect到位于Views文件夹中的index.ejs视图。 在我的routes.js文件中,我添加了这个: module.exports = function (app) { app.get('/', function(req, res) { res.render('index', {title: "TODO"}) }); } 索引视图包含所有页面的标记,因为它将是一个SPA,所以我将在客户端dynamic交换视图。 问题是,我引用脚本位于公用文件夹中,他们没有find,我得到一个404: script src="public/app/app.js"></script> 我想这是因为Express不知道如何服务器文件。 我已经指定公用文件夹中的所有内容都应该是静态文件: app.use(express.static(config.root + '/public')) 现在,如果我不使用ejs模板,并且如果我在公用文件夹而不是视图中使用index.html文件,它工作正常。 我只需要这样做: app.get('*', function(req, res) { res.sendfile('./public/index.html'); }); 但是我想利用ejs模板来添加bundle到页面,而不是逐个添加脚本。 那么我的代码有什么问题? 我怎样才能解决404文件的JavaScript文件?