AppML 如何使用

如何通过两个简单的步骤构建 AppML 应用程序。


1. 使用 HTML 和 CSS 创建页面

HTML

<!DOCTYPE html>
<html lang="en-US">
<link rel="stylesheet" href="style.css">
<title>Customers</title>
<body>

<h1>Customers</h1>

<table>
<tr>
  <th>Customer</th>
  <th>City</th>
  <th>Country</th>
</tr>
<tr>
  <td>{{CustomerName}}</td>
  <td>{{City}}</td>
  <td>{{Country}}</td>
</tr>
</table>

</body>
</html>
亲自试一试 »

{{ }} 括号是 AppML 数据的占位符。

CSS

body {
    font: 14px Verdana, sans-serif;
}
h1 {
    color: #996600;
}
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    border: 1px solid grey;
    padding: 5px;
    text-align: left;
}
table tr:nth-child(odd) {
    background-color: #f1f1f1;
}

随意将 CSS 替换为您自己喜欢的样式表。


2. 添加 AppML

使用 AppML 将数据添加到您的页面:

实例

<!DOCTYPE html>
<html lang="en-US">
<title>Customers</title>
<link rel="stylesheet" href="style.css">
<script src="https://www.w3schools.cn/appml/2.0.3/appml.js"></script>
<body>

<h1>Customers</h1>

<table appml-data="customers.js">
<tr>
  <th>Customer</th>
  <th>City</th>
  <th>Country</th>
</tr>
<tr appml-repeat="records">
  <td>{{CustomerName}}</td>
  <td>{{City}}</td>
  <td>{{Country}}</td>
</tr>
</table>

</body>
</html>
亲自试一试 »

AppML 代码解析:

<script src="https://www.w3schools.cn/appml/2.0.3/appml.js"> 将 AppML 添加到您的页面。

appml-data="customers.js" 将 AppML 数据 (customers.js) 连接到 HTML 元素 (<table>)。

在本例中,我们使用了 JSON 文件:customers.js

appml-repeat="records" 为数据对象中的每个项目(记录)重复一个 HTML 元素 (<tr>)。

{{ }} 括号是 AppML 数据的占位符。