[英]Convert javascript template to pure javascript
By using java i want to convert javascript template (i try to make ) to pure javascript 通过使用Java,我想将javascript模板(我尝试使)转换为纯javascript
Here is example : Input 这是示例:输入
<? function test()
{
return "Just a message";
}
if("a"=="b")
{
?>
<h1><?=test()?></h1>
<?
}
?>
<?=test()?>
</head></html>
output pure js example 输出纯js示例
out.print("<html><head>");
function test()
{
return "Just a message";
}
out.print("<h1>");
if("a"=="b")
{
out.print(test());
}
out.print("</h1>");
out.print("</head></html>");
I need a function to convert javascript template to pure javascript an eval it later . 我需要一个函数将javascript模板转换为纯javascript,稍后再进行评估。 p/sa example using javascript function here http://ejohn.org/blog/javascript-micro-templating/ but i'm not sure it work perfectly when given conplex template
p / sa在此处使用javascript函数的示例http://ejohn.org/blog/javascript-micro-templating/,但我不确定给定复杂模板时它是否能完美工作
You can match every pair. 您可以匹配每对。 And each pair is javascript and the rest is outputted using out.print(...).
每对都是javascript,其余的则使用out.print(...)输出。 A simple regex can do the job.
一个简单的正则表达式就可以完成这项工作。
Or you can look at template engines which are fully tested and supported, such as: http://mustache.github.io/ 或者,您可以查看经过全面测试和支持的模板引擎,例如: http : //mustache.github.io/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.