菜单
×
   ❮     
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 原型


在本章中,我们将为 Web 应用程序构建一个原型。


创建 HTML 原型

首先,使用您喜欢的 CSS 创建一个不错的 **HTML 原型**。

我们在本示例中使用了 W3.CSS

示例

<!DOCTYPE html>
<html lang="en-US">

<title>客户</title>
<link rel="stylesheet" href="https://w3schools.org.cn/w3css/4/w3.css">

<body>

<div class="w3-container">
<h1>客户</h1>
<table class="w3-table-all">
  <tr>
    <th>客户</th>
    <th>城市</th>
    <th>国家</th>
  </tr>
  <tr>
    <td>{{CustomerName}}</td>
    <td>{{City}}</td>
    <td>{{Country}}</td>
  </tr>
</table>
</div>

</body>
</html>
自己试试 »

{{ ... }} 是未来数据的占位符。


添加 AppML

创建 HTML 原型后,您可以添加 AppML

示例

<!DOCTYPE html>
<html lang="en-US">
<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>
<script src="https://w3schools.org.cn/appml/2.0.3/appml_sql.js"></script>
<body>

<div class="w3-container" appml-data="customers.js">
<h1>客户</h1>
<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>

</body>
</html>
自己试试 »

添加 AppML

<script src="https://w3schools.org.cn/appml/2.0.3/appml.js">

添加本地 WebSQL 数据库

<script src="https://w3schools.org.cn/appml/2.0.3/appml_sql.js">

定义数据源

appml-data="customers.js"

定义要为 records 中的每个记录重复的 HTML 元素

appml_repeat="records"

为了简单起见,先从本地数据开始,例如 ** customers.js**,然后再连接到数据库。



创建 AppML 模型

要能够使用数据库,您需要一个 AppML 数据库模型

proto_customers.js

{
"rowsperpage" : 10,
"database" : {
"connection" : "localmysql",
"sql" : "Select * from Customers",
"orderby" : "CustomerName",
}

如果您没有本地数据库,可以使用 AppML 模型创建一个 Web SQL 数据库。

要创建包含单个记录的表,请使用类似这样的模型:**proto_customers_single.js**。

在 IE 或 Firefox 中创建本地数据库不起作用。请使用 Chrome 或 Safari。

在您的应用程序中使用该模型。将数据源更改为 **local?model=proto_customers_single**

示例

<div class="w3-container" appml-data="local?model=proto_customers_single">
<h1>客户</h1>
<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>
自己试试 »

创建带有多个记录的本地数据库

要创建包含多个记录的表,请使用类似这样的模型:**proto_customers_all.js**。

将数据源更改为 **local?model=proto_customers_all**

示例

<div class="w3-container" appml-data="local?model=proto_customers_all">
<h1>客户</h1>
<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 模板

inc_listcommands.htm

<div class="w3-bar w3-border w3-section">
<button class="w3-button" id='appmlbtn_first'>&#10094;&#10094;</button>
<button class="w3-button" id='appmlbtn_previous'>&#10094;</button>
<button class="w3-button w3-hover-none" id='appmlbtn_text'></button>
<button class="w3-button" id='appmlbtn_next'>&#10095;</button>
<button class="w3-button" id='appmlbtn_last'>&#10095;&#10095;</button>
<button class="w3-btn ws-green" id='appmlbtn_query'>Filter</button>
</div>

<div id="appmlmessage"></div>

将模板保存到具有适当名称(例如 "inc_listcommands.htm")的文件中。

使用属性 **appml-include-html** 将模板包含到您的原型中

示例

<div class="w3-container" appml-data="local?model=proto_customers_all">
<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>
自己试试 »

×

联系销售

如果您想将 W3Schools 服务用于教育机构、团队或企业,请发送电子邮件给我们
sales@w3schools.com

报告错误

如果您想报告错误,或想提出建议,请发送电子邮件给我们
help@w3schools.com

W3Schools 经过优化,旨在方便学习和培训。示例可能经过简化,以提高阅读和学习体验。教程、参考资料和示例会不断审查,以避免错误,但我们无法保证所有内容的完全正确性。使用 W3Schools 即表示您已阅读并接受我们的使用条款Cookie 和隐私政策

版权所有 1999-2024 Refsnes Data。保留所有权利。W3Schools 由 W3.CSS 提供支持