您需要一个JavaScript模板引擎。第一个也是最好的之一是Handlebars.js。您可以使用它来创建一次布局,并将布局应用于您拥有的所有数据,这样,您可以将数据和表示分开。
说这是你的项目的基地布局:
<div class="entry">
<h1>{{title}}</h1>
<div class="body">
{{body}}
</div>
</div>
如果你有多个项目,则可以使用JSON作为饲料:
[
{
title: "My Post 1",
body: "This is my first post!"
},
{
title: "My Old Post",
body: "This is my first post!"
},
{
title: "My Latest Post",
body: "This is my first post!"
},
{
title: "My New Post",
body: "This is my first post!"
}
]
,您还可以采用同样的布局所有的四个职位!上面的代码获取客户端执行,这种方式:
<div class="entry">
<h1>My Post 1</h1>
<div class="body">
This is my first post!
</div>
</div>
<div class="entry">
<h1>My Old Post</h1>
<div class="body">
This is my first post!
</div>
</div>
<div class="entry">
<h1>My Latest Post</h1>
<div class="body">
This is my first post!
</div>
</div>
<div class="entry">
<h1>My New Post</h1>
<div class="body">
This is my first post!
</div>
</div>
有关执行,编译模板的详细信息,请参阅docs。
[JSON](http://www.w3schools.com/json/)是您的起点。 – Litestone 2014-10-27 13:18:39
所以当有人更新它时,使用该网站的其他人将如何看到这种变化? – tymeJV 2014-10-27 13:18:39
最终产品意味着作为不可修改的帮助部分在软件中本地分发。修改只能由软件开发人员在制作软件时进行(例如编写软件属性描述) – acerne 2014-10-27 13:25:34