AppMLวิธีการ
วิธีสร้าง AppML Application ใน2 ขั้นตอนง่ายๆ
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.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>
AppML อธิบาย:
<script src="https://www.w3schools.com/appml/2.0.3/appml.js"> เพิ่ม AppML ในหน้าของคุณ
appml-data = "customers.js"เชื่อมต่อข้อมูล AppML (customers.js) กับองค์ประกอบ HTML (<table>)
ในกรณีนี้ เราใช้ไฟล์ JSON:
appml-repeat="records" ทำซ้ำองค์ประกอบ HTML (<tr>) สำหรับแต่ละรายการ (ระเบียน) ในวัตถุข้อมูล
วงเล็บ {{ }} เป็น ตัว ยึดตำแหน่งสำหรับข้อมูล AppML