我读了很多关于MVC架构的文章,但我仍然感到困惑.
图1
图1 http://img219.imageshack.us/img219/4576/screenshot20100418at213.png
图2
图2 http://img38.imageshack.us/img38/4576/screenshot20100418at213.png
图3
图3 http://img526.imageshack.us/img526/3900/screenshot20100418at214.png
能否请您解释一下,JavaScript中的模板引擎如何工作?谢谢.
JSON
{ "color" : "red"}
Run Code Online (Sandbox Code Playgroud)
模板
<strong><%=color%></strong>
Run Code Online (Sandbox Code Playgroud)
结果
<strong>Red</strong>
Run Code Online (Sandbox Code Playgroud) 如何提醒变量名,而不是变量值?
var color = 'red';
alert(color); // Will alert 'red'
alert(/* magic */); // Will alert 'color'
Run Code Online (Sandbox Code Playgroud) 我想用JavaScript 创建通用模板引擎,怎么样?
HTML模板
<h1><%title1%></h1>
<h2><%title2%></h2>
Run Code Online (Sandbox Code Playgroud)
JSON文件
{
"title1" : "Hello World!",
"title2" : "Hi World!"
}
Run Code Online (Sandbox Code Playgroud)
使用Javascript
对于<%title2%>也是如此
谢谢!