ตัวควบคุมAppML
วัตถุประสงค์ของตัวควบคุม AppMLคือเพื่อให้คุณควบคุมแอปพลิเคชันของคุณ
ผู้ควบคุมสามารถทำอะไรได้บ้าง
- ตั้งค่าข้อมูลเริ่มต้น
- เปลี่ยนข้อมูลแอปพลิเคชัน
- จัดการอินพุตและเอาต์พุต
- ตรวจสอบข้อมูล
- สรุปข้อมูล
- จัดการข้อผิดพลาด
- เริ่มและหยุดแอปพลิเคชัน
- และอีกมากมาย
ไม่มีคอนโทรลเลอร์
โดยค่าเริ่มต้น แอปพลิเคชัน AppML จะทำงานโดยไม่มีตัวควบคุม:
ตัวอย่าง
<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>
ด้วยคอนโทรลเลอร์
ด้วยตัวควบคุม AppML คุณสามารถควบคุม แอปพลิเคชัน ของคุณด้วย JavaScript
ตัวควบคุมเป็นฟังก์ชัน JavaScript ที่คุณจัดเตรียมให้
แอตทริบิวต์appml-controllerใช้เพื่ออ้างถึงฟังก์ชันตัวควบคุม
ตัวอย่าง
<h1>Customers</h1>
<table appml-data="customers.js" appml-controller="myController">
<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>
<script>
function myController($appml) {
if ($appml.message == "display") {
if ($appml.display.name == "CustomerName")
{
$appml.display.value = $appml.display.value.toUpperCase();
}
}
}
</script>
ตัวควบคุม (myController) ในตัวอย่างข้างต้น จะเปลี่ยนค่าของ "CustomerName" เป็นตัวพิมพ์ใหญ่ก่อนที่จะแสดง
หากคุณมีคอนโทรลเลอร์ AppML จะส่งออบเจ็กต์แอปพลิเคชัน ($appml) ไปยังคอนโทรลเลอร์ สำหรับทุกการกระทำที่สำคัญ
หนึ่งในคุณสมบัติของแอปพลิเคชันคือข้อความ ($appml.message) ที่อธิบายสถานะของแอปพลิเคชัน
Message | Description |
---|---|
ready | Sent after AppML is initiated, and ready to load data. |
loaded | Sent after AppML is fully loaded, ready to display data. |
display | Sent before AppML displays a data item. |
done | Sent after AppML is done (finished displaying). |
submit | Sent before AppML submits data. |
error | Sent after AppML has encountered an error. |
จะมีการอธิบายข้อความในบทต่อไป