本章將介紹如何構建對數據庫的輸入形式。
此頁面上的示例使用本地SQL數據庫。
本地SQL數據庫不能在IE或Firefox的工作。 使用Chrome或Safari。
創建一個表單模型
model_customersform.js
{
"database" : {
"connection" : "localmysql",
"maintable" : "Customers",
"keyfield" : "CustomerID",
"sql" : "SELECT * FROM Customers"},
"updateItems" : [
{"item" : "CustomerName"},
{"item" : "Address"},
{"item" : "PostalCode"},
{"item" : "City"},
{"item" : "Country"}]
}
創建HTML表單
在前面的章節中,您創建從數據庫中列出的記錄的應用程序。
現在添加一個表單應用程序頁面:
HTML表單
<div id="Form01" appml-data="local?model=model_customersform"
class="jumbotron">
<div class="form-group">
<label for="customername">Customer:</label>
<input id="customername" class="form-control">
</div>
<div class="form-group">
<label
for="address">Address:</label>
<input id="address" class="form-control">
</div>
<div class="form-group">
<label for="city">City:</label>
<input id="city" class="form-control">
</div>
<div
class="form-group">
<label for="postalcode">Postal Code:</label>
<input id="postalcode"
class="form-control">
</div>
<div class="form-group">
<label
for="country">Country:</label>
<input id="country" class="form-control">
</div>
</div>
試一試» HTML表單解釋
appml數據=“本地?模型= model_customersform”定義為窗體AppML應用。
創建HTML表單命令
使用您喜歡的樣式表(we use bootstrap)並創建你想要的格式的命令:
inc_formcommands.htm
<button type="button" class="close"
onclick="document.getElementById('Form01').style.display='none';">X</button>
<button type="button" class="close">X</button>
<div class="btn-toolbar" style="margin-bottom:20px;">
<div class="btn-group">
<button type="button" class="btn btn-default" onclick="appml('Form01').newRecord();">
<span class="glyphicon glyphicon-new-window"></span> New</button>
<button type="button" class="btn btn-primary" onclick="appml('Form01').saveRecord();">
<span class="glyphicon glyphicon-floppy-disk"></span> Save</button>
<button type="button" class="btn btn-default" onclick="appml('Form01').deleteRecord();">
<span class="glyphicon glyphicon-trash"></span> Delete</button>
</div>
</div>
<div id="appmlmessage" class="alert alert-warning" style="display:none;">
<button type="button" class="close"
onclick="this.parentNode.style.display='none';">X</button>
<div id="message"></div>
</div>
包括下列形式的命令
包括在你的表格形式命令在:.
HTML表單
<div id="Form01" appml-data="local?model=model_customersform"
class="jumbotron">
<div appml-include-html="inc_formcommands.htm"></div>
<div class="form-group">
<label for="customername">Customer:</label>
<input id="customername" class="form-control">
</div>
<label
for="address">Address:</label>
<input id="address" class="form-control">
</div>
<div class="form-group">
<label for="city">City:</label>
<input id="city" class="form-control">
</div>
<div
class="form-group">
<label for="postalcode">Postal Code:</label>
<input id="postalcode"
class="form-control">
</div>
<div class="form-group">
<label
for="country">Country:</label>
<input id="country" class="form-control">
</div>
</div>
試一試» 可點擊列添加到表
在前面的章節中,您創建從數據庫中列出的記錄的應用程序。
現在添加一個新列到表:
HTML源代碼
<div appml-data="local?model=model_customerslist">
<h1>Customers</h1>
<div appml-include-html="inc_listcommands.htm"></div>
<div appml-include-html="inc_filter.htm"></div>
<table class="table table-striped table-bordered">
<tr>
<th></th>
<th>Customer</th>
<th>City</th>
<th>Country</th>
</tr>
<tr appml-repeat="records">
<td
style="cursor:pointer;width:34px;"
onclick="appml('Form01').run({{CustomerID}})">
<span class="glyphicon glyphicon-edit"></span></td>
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
</div>
試一試» onclick事件(in the new column)觸發呼叫運行位於使用id =“Form01”的HTML元素的AppML應用:
- appml('Form01')返回AppML應用
- run({{CustomerID}})行具有CustomerID作為參數的應用程序。
最後,隱藏窗體
樣式添加到窗體,以使其不可見:
HTML
<div id="Form01" appml-data="local?model=model_customersform"
appml-controller="myFormController"
class="jumbotron" style="display:none" >
控制器添加到窗體,以顯示形式,只有當它被加載,並準備顯示數據:
調節器
<script>
function myFormController($appml) {
if ($appml.message
== "ready") {return -1;}
if ($appml.message ==
"loaded") {
document.getElementById("Form01").style.display="";
}
}
</script>
試一試»