本章将介绍如何构建对数据库的输入形式。
此页面上的示例使用本地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>
试一试»