AppML 列表
在本章中,我們將列出資料庫中的記錄。
本頁上的示例使用本地 SQL 資料庫。
本地 SQL 資料庫在 IE 或 Firefox 中不起作用。請使用 Chrome 或 Safari。
建立新模型
在上一章中,您使用了一個模型來建立資料庫。
現在建立一個新模型,包括篩選器和排序定義
model_customerslist.js
{
"rowsperpage" : 10,
"database" : {
"connection" : "localmysql",
"sql" : "SELECT * FROM Customers",
"orderby" : "CustomerName"
},
"filteritems" : [
{"item" : "CustomerName", "label" : "客戶"},
{"item" : "城市"},
{"item" : "國家"}
],
"sortitems" : [
{"item" : "CustomerName", "label" : "客戶"},
{"item" : "城市"},
{"item" : "國家"}
]
}
在應用程式中使用模型
示例
<div appml-data="local?model=model_customerslist">
<h1>客戶</h1>
<div appml-include-html="inc_listcommands.htm"></div>
<table class="w3-table-all">
<tr>
<th>客戶</th>
<th>城市</th>
<th>國家</th>
</tr>
<tr appml-repeat="records">
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
</div>
自己試試 »
建立 HTML 篩選器模板
為您的篩選器建立 HTML
inc_filter.htm
<div id="appml_filtercontainer" class="w3-container w3-light-grey w3-section w3-padding-large" style="display:none;">
<span id="appmlbtn_queryClose" onclick="this.parentNode.style.display='none';" class="w3-button w3-large w3-right">×</span>
<h2>篩選</h2>
<div id="appml_filter">
<div appml-repeat="filteritems">
<div class="w3-row">
<div class="w3-col m4">
<label>{{label||item}}:</label>
</div>
<div class="w3-col m2">
<input id="appml_datatype_{{item}}" type='hidden'>
<select id="appml_operator_{{item}}" class="w3-select w3-border">
<option value="0">=</option>
<option value="1"><></option>
<option value="2"><</option>
<option value="3">></option>
<option value="4"><=</option>
<option value="5">>=</option>
<option value="6">%</option>
</select>
</div>
<div class="w3-col m6">
<input id="appml_query_{{item}}" class="w3-input w3-border">
</div>
</div>
</div>
</div>
<div id="appml_orderby">
<h2>排序</h2>
<div class="w3-row">
<div class="w3-col m5">
<select id='appml_orderselect' class="w3-select w3-border">
<option value=''></option>
<option appml-repeat="sortitems" value="{{item}}">{{label || item}}</option>
</select>
</div>
<div class="w3-col m7">
ASC <input type='radio' id="appml_orderdirection_asc" name='appml_orderdirection' value='asc' class="w3-radio">
DESC <input type='radio' id="appml_orderdirection_desc" name='appml_orderdirection' value='desc' class="w3-radio">
</div>
</div>
</div>
<br>
<button id="appmlbtn_queryOK" type="button" class="w3-btn w3-green">OK</button>
</div>
將篩選器 HTML 儲存在一個具有適當名稱的檔案中,例如 "inc_filter.htm"。
使用 appml-include-html 將篩選器 HTML 包含在您的原型中
示例
<div appml-data="local?model=model_customerslist">
<h1>客戶</h1>
<div appml-include-html="inc_listcommands.htm"></div>
<div appml-include-html="inc_filter.htm"></div>
<table class="w3-table-all">
<tr>
<th>客戶</th>
<th>城市</th>
<th>國家</th>
</tr>
<tr appml-repeat="records">
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
</div>
自己試試 »