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进行节点开发?

它看起来像甚至没有在源代码中定义,这让我想知道为什么它在他们的wiki页面上。 我从另一个答案中find了一个名为express-helpers的包,它在configuration时允许访问所有的视图助手。

 npm install express-helpers 

在你的app.js中,configuration它:

 require('express-helpers')(app); 

最后,你的观点会有所不同:

 <% var choices = [ {value: 1,text: 'First Choice'}, {value: 2,text: 'Second Choice'}, {value: 3,text: 'Third Choice'} ] %> <%- select_tag('mySelectElement', choices, { value: 2 }) %> 

select_tag具有以下参数:

 name choices html_options id name value (selected value)