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óm tắt dữ liệu
- Xử lý lỗi
- Bắt đầu 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ần bộ điều khiển:
Ví 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>
Hãy tự mình thử » Với 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ỉ chức năng của bộ điều khiển.
Ví 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>
Hãy tự mình thử »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) đến 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à một 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. |
Tin nhắn được giải thích trong chương tiếp theo.