【问题标题】:Visionmedia EJS on Client side ( Cordova / PhoneGap )?客户端(Cordova / PhoneGap)上的 Visionmedia EJS?
【发布时间】:2015-02-06 11:19:08
【问题描述】:

我一直在开发一个 Cordova 应用程序。

我知道 Visionmedia EJS 是一个服务器端工具。 我可以在没有 node.js 的客户端上使用 Visionmedia EJS 吗?

例如,我想为我的应用程序创建 3 个部分。这些部分是 layout.ejs、homepage.ejs 和 user.ejs(一个子页面)。我可以像下面这样安排吗?有可能吗?

我的布局 EJS 文件

<!DOCTYPE html>
<html>
  <body>
    <%- body %>
  </body>
</html>

我的主页 EJS 文件

<div>
    <% include user.ejs %>
</div>

我的 user.ejs 文件

<div data-role="page" id="page-user">
    username: <%- user.username %>
    firstname: <%- user.firstname %>
    lastname: <%- user.lastname %>
</div>

【问题讨论】:

    标签: cordova client-side porting ejs embedded-javascript


    【解决方案1】:

    使用以下流程:

    • 下载 EJS 源文件
    • 在 HTML 页面中将它们作为 src&lt;script&gt; 标签引用

    这是一个例子:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
    <head>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <title>EJS - Embedded JavaScript - Demo</title>
        <link rel="stylesheet" href="example.css" type="text/css" media="screen" />
        <script src="../lib/prototype.js" type="text/javascript"></script>
        <script src="../src/ejs.js" type="text/javascript"></script>
        <script src="example.js" type="text/javascript"></script>
    </head>
    
    <body id="thebod">
    <h1><a href="http://www.edwardbenson.com/projects/ejs/"><img src="ejs.gif" alt="EJS - Embedded JavaScript" /></a></h1>
    <h2>Demo Page</h2>
    <p>This page is a quickly cobbled together demo of compiling EJS from a DOM source and from a String source. For more information and demos, see <a href="http://www.edwardbenson.com/projects/ejs">EJS on the web</a>.</p>
    
    <div class="example">
    <h3>Example 1: Running from the a String</h3>
    <h4><a href="#" onClick="testUsingText();return false;">Run</a></h4>
    <p>This example compiles and runs EJS from a String stored in the example.js file included with this project.</p>
    </div>
    
    <div class="example">
    <h3>Example 2: Running from the DOM </h3>
    <h4><a href="#" onClick="testUsingDOM();return false;">Run</a></h4>
    <p>This example compiles and runs EJS from the DOM node directly below this sentence.</p>
    <div id="source_code">
    [%  var title = "Items to buy!"; %]
    <h1>[%= title %]</h1>
    <ul>
    [% ['cupcake', 'hardware'].each(function(item) { %]<li>[%= item %]</li>[% }); %]
    </ul>
    </div>
    </div>
    <hr>
    <div class="output">
    <h3>Compiled Code</h3>
    
    <div id="output_code">
    </div>
    </div>
    <div class="output">
    <h3>Compilation Results</h3>
    <div id="output_results">
    </div>
    </div>
    <br />
    
    </div>
    <br /><br /><br />
    <p align="center">Copyright &copy; 2007 Edward Benson<br /><a href="http://www.edwardbenson.com/">edwardbenson.com</a></p>
    </body>
    </html>
    

    参考文献

    【讨论】:

    • 感谢 Paul,现在我可以在我的 Cordova 项目中使用 EJS。除了 layout.ejs。无论如何,谢谢,我给你的漂亮回复 +1 点赞。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 1970-01-01
    • 2020-06-19
    • 1970-01-01
    相关资源
    最近更新 更多