是否有像handlebars/dust(我可以使用它和如何?)或更智能的方式來生成在Appcelerator/Titanium上的HTML?Appcelerator/Titanium HTML塊/模板生成
基本上我需要用對象數組中的數據填充HTML模板(特別是表格)。我寧願轉義字符串連接,因爲它很醜並且容易失敗。我已經廣泛搜索,但無法找到答案。
我探索的一個選項是將我的HTML文件加載到WebView中,在其中創建一個腳本,然後使用WebView的evalJS()並將我的數據從Titanium傳遞給它。然而,這需要將另一個函數編碼到操縱DOM的HTML文件中(這將是很多工作),並且此後我需要解析它並將其取消,因爲我不希望這部分是接收器可見(以防他們打開信號源)。例如:
var data = [{a:a}, {a:b}, {a:c}];
var webview = Titanium.UI.createWebView({url:'my_template.html'});
var str = "Hello world!";
webview.evalJS("generateTable('"data"');");
,然後在HTML
function generateTable(data) {
//manipulate the DOM to create the table and add the properties...
}
是否有某種方式利用塊/ HTML模板(示例):
<div class="main">
<table sortable="sortable">
{% loop in $users as $user %}
<tr>
<td class='center'>{$data.id}</td>
<td class='center'>{$data.date}</td>
<td class='center'>{$data.name}</td>
<td class='center'>{$data.email}</td>
</tr>
{% endloop %}
</table>
任何建議/樣品很樂意可以理解,謝謝!