AppML Cách thực hiện
Cách tạo Ứng dụng AppML trong 2 bước đơn giản .
1. Tạo trang bằng HTML và 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>
Dấu ngoặc {{}} là phần giữ chỗ cho dữ liệu 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;
}
Hãy thay thế CSS bằng biểu định kiểu yêu thích của riêng bạn.
2. Thêm AppML
Sử dụng AppML để thêm dữ liệu vào trang của bạn:
Thí dụ
<!DOCTYPE html>
<html lang="en-US">
<title>Customers</title>
<link rel="stylesheet" href="style.css">
<script src="https://www.w3schools.com/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>
Giải thích về AppML:
<script src = "https://www.w3schools.com/appml/2.0.3/appml.js"> thêm AppML vào trang của bạn.
appml-data = "customer.js" kết nối dữ liệu AppML (customer.js) với một phần tử HTML (<table>).
Trong trường hợp này, chúng tôi đã sử dụng tệp JSON:
appml-repeat = "records" lặp lại một phần tử HTML (<tr>) cho mỗi mục (bản ghi) trong một đối tượng dữ liệu.
Dấu ngoặc {{}} là phần giữ chỗ cho dữ liệu AppML.