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.tw/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.tw/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 資料的佔位符。