Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

AppML 表单


本章演示如何针对数据库构建输入表单。


本页示例使用本地 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" class="w3-container w3-light-grey w3-padding-large w3-margin-bottom" appml-data="local?model=model_customersform">

<p>
<label for="customername">客户:</label>
<input id="customername" class="w3-input w3-border">
</p>

<p>
<label for="address">地址:</label>
<input id="address" class="w3-input w3-border">
</p>

<p>
<label for="city">城市:</label>
<input id="city" class="w3-input w3-border">
</p>

<p>
<label for="postalcode">邮政编码:</label>
<input id="postalcode" class="w3-input w3-border">
</p>

<p>
<label for="country">国家:</label>
<input id="country" class="w3-input w3-border">
</p>

</div>
动手试试 »

HTML 表单说明

appml-data="local?model=model_customersform" 定义了表单的 AppML 应用程序。



创建 HTML 表单命令

使用您喜欢的样式表(我们使用 bootstrap),并创建您想要的表单命令

inc_formcommands.htm

<span onclick="document.getElementById('Form01').style.display='none'" class="w3-button w3-xlarge w3-right">&times;</span>

<div class="w3-bar w3-border w3-white">
<button onclick="appml('Form01').newRecord();" class="w3-btn">新建</button>
<button onclick="appml('Form01').saveRecord();" class="w3-btn w3-green">保存</button>
<button onclick="appml('Form01').deleteRecord();" class="w3-btn">删除</button>
</div>

<div id="appmlmessage" class="w3-container w3-pale-yellow w3-padding" style="display:none;">
<span onclick="this.parentNode.style.display='none';" class="w3-button w3-xlarge w3-right">&times;</span>
<div id="message"></div>
</div>

包含表单命令

在您的表单中包含表单命令

HTML 表单

<div id="Form01" class="w3-container w3-light-grey w3-padding-large w3-margin-bottom" appml-data="local?model=model_customersform">

<div appml-include-html="inc_formcommands.htm"></div>

<p>
<label for="customername">客户:</label>
<input id="customername" class="w3-input w3-border">
</p>

<p>
<label for="address">地址:</label>
<input id="address" class="w3-input w3-border">
</p>

<p>
<label for="city">城市:</label>
<input id="city" class="w3-input w3-border">
</p>

<p>
<label for="postalcode">邮政编码:</label>
<input id="postalcode" class="w3-input w3-border">
</p>

<p>
<label for="country">国家:</label>
<input id="country" class="w3-input w3-border">
</p>

</div>
动手试试 »

在表格中添加一个可点击的列

在上一章中,您创建了一个用于列出数据库中记录的应用程序。

现在在表格中添加一个新列

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>
    <th>国家</th>
  </tr>
  <tr appml-repeat="records">
    <td style="cursor:pointer;width:34px;" onclick="appml('Form01').run({{CustomerID}})">&#9998;</td>
    <td>{{CustomerName}}</td>
    <td>{{City}}</td>
    <td>{{Country}}</td>
  </tr>
</table>

</div>
动手试试 »

onclick 事件(在新列中)会触发调用运行位于 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>
动手试试 »

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.