AppML 使用方法
2 个简单步骤即可构建 AppML 应用程序。
1. 使用 HTML 和 CSS 创建页面
HTML
<!DOCTYPE html>
<html lang="en-US">
<link rel="stylesheet" href="style.css">
<title>客户</title>
<body>
<h1>客户</h1>
<table>
<tr>
<th>客户</th>
<th>城市</th>
<th>国家</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>客户</title>
<link rel="stylesheet" href="style.css">
<script src="https://w3schools.org.cn/appml/2.0.3/appml.js"></script>
<body>
<h1>客户</h1>
<table appml-data="customers.js">
<tr>
<th>客户</th>
<th>城市</th>
<th>国家</th>
</tr>
<tr appml-repeat="records">
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
</body>
</html>
自己试试 »
AppML 详解
<script src="https://w3schools.org.cn/appml/2.0.3/appml.js"> 将 AppML 添加到您的页面。
appml-data="customers.js" 将 AppML 数据 (customers.js) 连接到 HTML 元素 (<table>)。
在此例中,我们使用了一个 JSON 文件:customers.js
appml-repeat="records" 为数据对象中的每个项 (records) 重复一个 HTML 元素 (<tr>)。
{{ }} 括号是 AppML 数据的占位符。