您需要一個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