Bộ điều khiển AppML
Mục đích của bộ điều khiển AppML là cho phép bạn kiểm soát ứng dụng của mình.
Bộ điều khiển có thể làm gì?
- Đặt dữ liệu ban đầu
- Thay đổi dữ liệu ứng dụng
- Xử lý đầu vào và đầu ra
- Xác thực dữ liệu
- Tổng hợp dữ liệu
- Xử lý lỗi
- Khởi động và dừng ứng dụng
- Và nhiều hơn nữa
Không có Bộ điều khiển
Theo mặc định, các ứng dụng AppML chạy mà không có bộ điều khiển:
Thí dụ
<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>
Với một bộ điều khiển
Với bộ điều khiển AppML, bạn có thể kiểm soát ứng dụng của mình bằng JavaScript .
Bộ điều khiển là một hàm JavaScript, do bạn cung cấp .
Thuộc tính appml-controller được sử dụng để chỉ một hàm điều khiển.
Thí dụ
<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>
Bộ điều khiển (myController) trong ví dụ trên, thay đổi giá trị của "CustomerName" thành chữ hoa, trước khi nó được hiển thị.
Nếu bạn có bộ điều khiển, AppML sẽ gửi đối tượng ứng dụng ($ appml) tới bộ điều khiển, cho mọi hành động quan trọng.
Một trong những thuộc tính của ứng dụng là thông báo ($ appml.message), mô tả trạng thái ứng dụng.
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. |
Thông điệp được giải thích trong chương tiếp theo.