Clouda第一App“留言大廳”之創(chuàng)建hall.js
首先預(yù)覽一下"留言大廳"
在"留言大廳"這個應(yīng)用中,用戶可以在這里留言,也可以看到別人的留言。
因為需要存儲留言,所以在正式開始之前我們需要先安裝MongoDB,并在127.0.0.1的27017端口上啟動(此地址可在 app/server_config/database.js中進(jìn)行配置),MongoDB是我們依賴的數(shù)據(jù)庫,在以后各種應(yīng)用中都會經(jīng)常用到。
在app/view/
下創(chuàng)建hall.html
-
hall.html
- <style>
- button{width:100px; height:40px;}
- #content{width:360px;height:300px;margin-top:10px;}
- </style>
- <div align="center">
- <h1>Clouda message Hall</h1>
- <input style="height:40px; width:260px;padding-left: 5px;" id="messageInput" placeholder="Say Something Now:"/>
- <button class="messageSubmit">submit</button> <br/>
- <block tpl-id="message-hall">
- <textarea readonly="readonly" id="content">
- {{#each data}}
- {{this.content}}
- {{/each}}
- </textarea><br/>
- </block>
- <button class="clearHistory">clear history</button>
- </div>
與上一篇文檔中我們看到的View不同,這次hall.html中多了"{{this.content}}",這是插入模板渲染所需的數(shù)據(jù)變量,Clouda使用
handlebars
組件作為模板引擎,關(guān)于handlebars語法請查看handlebars官網(wǎng)。
至此,App代碼部分已經(jīng)完成。