ล่าสุดการพัฒนาเว็บบทเรียน
 

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>
ลองตัวเอง»

ตัวควบคุม (myControlller) ในตัวอย่างข้างต้นเปลี่ยนค่าของ "CustomerName" เป็นตัวพิมพ์ใหญ่ก่อนที่มันจะปรากฏขึ้น

ถ้าคุณมีตัวควบคุม, AppML จะส่งวัตถุแอพลิเคชัน ($appml) ไปยังตัวควบคุมสำหรับการดำเนินการที่สำคัญทุก

หนึ่งในคุณสมบัติสมัครเป็นข้อความ ($appml.message) อธิบายรัฐแอพลิเคชัน

ข่าวสาร ลักษณะ
ready ส่งหลังจาก AppML เริ่มต้นขึ้นและพร้อมที่จะโหลดข้อมูล
loaded ส่งหลังจาก AppML เป็นแปล้พร้อมที่จะแสดงข้อมูล
display ส่งก่อน AppML แสดงรายการข้อมูล
done ส่งหลังจาก AppML จะทำ (finished displaying)
submit ส่งก่อน AppML ส่งข้อมูล
error ส่งหลังจาก AppML พบข้อผิดพลาด

ข้อความจะถูกอธิบายในบทต่อไป