只需在此处发布此答案,以供在解决同一问题时可能会遇到此问题的人。
您所需要做的就是创建一个新文件(例如functions.ejs
),并将其包含在您要调用该函数的.ejs文件中。因此,我在名为的文件中具有这样的功能functions.ejs
:
<%
getPriceChgArrow = function(value) {
arrow_img_name = "";
if (value < 0) {
arrow_img_name = "arrow_down12x13.gif";
}
else {
arrow_img_name = "arrow_up12x13.gif";
}
return arrow_img_name;
}
%>
然后将其包含functions.ejs
在您要从中调用函数的文件中。说,我想在quote.ejs
文件中调用此函数。因此,我将其包括如下:
<% include *file_path*/functions %>
<img src = "http:/some_url/<% getPriceChgArrow(data_point[0].value) %>" />
你们都准备好了。希望这对某人有帮助。