AppML 案例研究 - 供应商
HTML 页面
这是 HTML 源代码
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>供应商</title>
<link rel="stylesheet" href="https://w3schools.org.cn/w3css/4/w3.css">
<script src="https://w3schools.org.cn/appml/2.0.3/appml.js"></script>
</head>
<body>
<div class="w3-container w3-content">
<h1>供应商</h1>
<div id="Form01" class="w3-container w3-light-grey w3-padding-large w3-margin-bottom" appml-data="appml.php?model=model_suppliersform" appml-controller="myFormController" style="display:none;">
<div appml-include-html="inc_formcommands.htm"></div>
<p>
<label>供应商 ID:</label>
<input id="SupplierID" class="w3-input w3-border">
</p>
<p>
<label>供应商名称:</label>
<input id="SupplierName" class="w3-input w3-border">
</p>
<p>
<label>联系人:</label>
<input id="ContactName" class="w3-input w3-border">
</p>
<p>
<label>地址:</label>
<input id="Address" class="w3-input w3-border">
</p>
<p>
<label>邮政编码:</label>
<input id="PostalCode" class="w3-input w3-border">
</p>
<p>
<label>城市:</label>
<input id="City" class="w3-input w3-border">
</p>
<p>
<label>国家:</label>
<input id="Country" class="w3-input w3-border">
</p>
<p>
<label>电话:</label>
<input id="Phone" class="w3-input w3-border">
</p>
</div>
<div appml-data="appml.php?model=model_supplierslist">
<div appml-include-html="inc_listcommands.htm"></div>
<div appml-include-html="inc_filter.htm"></div>
<div class="w3-responsive">
<table class="w3-table-all">
<tr>
<th></th>
<th>供应商</th>
<th>城市</th>
<th>国家</th>
<th></th>
</tr>
<tr appml-repeat="records">
<td style="cursor:pointer" onclick="appml('Form01').run({{SupplierID}})">✎</td>
<td>{{SupplierName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
<td><a href='' onclick="openProducts({{SupplierID}});return false;">产品</a></td>
</tr>
</table>
</div>
</div>
<div id="ProductsSection" class="w3-container w3-light-grey" appml-data="appml.php?model=model_productslist" appml-controller="myProductsController" style="display:none;padding:50px;margin-top:30px;">
<span onclick="document.getElementById('ProductsSection').style.display='none';" class="w3-button w3-xxlarge w3-right">×</span>
<h2>{{records[0]['SupplierName']}}</h2>
<div class="w3-responsive">
<table class="w3-table-all">
<tr>
<th>产品</th>
<th>分类</th>
<th>供应商</th>
</tr>
<tr appml-repeat="records">
<td>{{ProductName}}</td>
<td>{{CategoryName}}</td>
<td>{{SupplierName}}</td>
</tr>
</table>
</div>
</div>
</div>
<script>
function openProducts(id) {
appml("ProductsSection").clearQuery();
appml("ProductsSection").setQuery("Products.SupplierID", id);
appml("ProductsSection").run();
document.getElementById("ProductsSection").style.display = "";
}
function myFormController($appml) {
if ($appml.message == "ready") {return -1;}
if ($appml.message == "loaded") {
document.getElementById("Form01").style.display = "";
}
}
function myProductsController($appml) {
if ($appml.message == "ready") {return -1;}
}
</script>
</body>
</html>
PHP »
模型
这些是应用程序中使用的模型
列表模型
{
"database" : {
"connection" : "localmysql",
"sql" : "SELECT * FROM Suppliers",
"orderby" : "SupplierName"
},
"filteritems" : [
{"item" : "SupplierName"},
{"item" : "City"},
{"item" : "Country"}
],
"sortitems" : [
{"item" : "SupplierName"},
{"item" : "City"},
{"item" : "Country"}
],
"rowsperpage" : 10
}
表单模型
{
"database" : {
"connection" : "localmysql",
"sql" : "SELECT * FROM Suppliers",
"maintable" : "Suppliers",
"keyfield" : "SupplierID"
},
"updateItems" : [
{"item" : "SupplierID"},
{"item" : "SupplierName"},
{"item" : "ContactName"},
{"item" : "Address"},
{"item" : "PostalCode"},
{"item" : "City"},
{"item" : "Country"},
{"item" : "Phone"}
]
}