AppML Mesajları
AppML Mesajları ve Eylemleri
AppML bir eylemi gerçekleştirmek üzereyken, uygulama nesnesini ($appml) denetleyiciye gönderir.
Uygulama nesnesinin özelliklerinden biri, uygulama durumunu açıklayan bir mesajdır ($appml.message).
Bu mesajı test etmek, eyleme bağlı olarak kendi JavaScript kodunuzu eklemenizi sağlar.
Örnek
function myController($appml) {
if ($appml.message == "ready") {alert ("Hello
Application");}
}
AppML Mesajları
Bu, alınabilecek AppML mesajlarının bir listesidir:
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. |
"Hazır" Mesajı
Bir AppML uygulaması veri yüklemeye hazır olduğunda "hazır" mesajı gönderir.
Bu, uygulamaya ilk verileri (başlangıç değerleri) sağlamak için mükemmel bir yerdir:
Örnek
<div appml-controller="myController" appml-data="customers.js">
<h1>Customers</h1>
<p>{{today}}</p>
<table>
<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>
<p>Copyright {{copyright}}</p>
</div>
<script>
function myController($appml) {
if ($appml.message == "ready") {
$appml.today = new Date();
$appml.copyright = "W3Schools"
}
}
</script>
Yukarıdaki örnekte, $appml.message "hazır" olduğunda, denetleyici uygulamaya iki yeni özellik ekler ( bugün ve telif hakkı ).
Uygulama çalıştığında, yeni özellikler uygulama için kullanılabilir hale gelir.
"Yüklendi" Mesajı
Bir AppML uygulaması verilerle yüklendiğinde (görüntülemeye hazır), " yüklendi " mesajı gönderir.
Bu, yüklenen verilerde değişiklik (gerekirse) sağlamak için mükemmel bir yerdir.
Örnek
function myController($appml) {
if ($appml.message == "loaded") {
// compute your values here before display
}
}
"Ekran" Mesajı
AppML bir veri öğesini her görüntülediğinde, bir " göster " mesajı gönderir.
Çıktıyı değiştirmek için mükemmel bir yer:
Örnek
<div appml_app="myController" appml-data="customers.js">
<h1>Customers</h1>
<table>
<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>
</div>
<script>
function myController($appml) {
if
($appml.message == "display") {
if ($appml.display.name ==
"CustomerName") {
$appml.display.value = $appml.display.value.substr(0,15);
}
if ($appml.display.name == "Country") {
$appml.display.value = $appml.display.value.toUpperCase();
}
}
}
</script>
Yukarıdaki örnekte, "MüşteriAdı" 15 karaktere kısaltılmıştır ve "Ülke" büyük harfe dönüştürülmüştür.
"Bitti" Mesajı
Bir AppML uygulaması verileri görüntülemeyi bitirdiğinde bir " bitti " mesajı gönderir.
Bu, uygulama verilerini (görüntülemeden sonra) temizlemek veya hesaplamak için mükemmel bir yerdir.
Örnek
<script>
function myController($appml) {
if ($appml.message == "done") {
calculate data here
}
}
</script>
"Gönder" Mesajı
Bir AppML uygulaması veri göndermeye hazır olduğunda bir " gönder " mesajı gönderir.
Bu, uygulama girişini doğrulamak için mükemmel bir yerdir.
Örnek
<script>
function myController($appml) {
if ($appml.message == "submit") {
validate data here
}
}
</script>
"Hata" Mesajı
Bir hata oluşursa, AppML bir " hata " mesajı gönderir.
Bu, hataları işlemek için mükemmel bir yerdir.
Örnek
<script>
function myController($appml) {
if ($appml.message ==
"error") {
alert ($appml.error.number + " " + $appml.error.description)
}
}
</script>
AppML Özellikleri
Bu, yaygın olarak kullanılan bazı AppML özelliklerinin listesidir:
Property | Description |
---|---|
$appml.message | The current state of the application. |
$appml.display.name | The name of the data field about to be displayed. |
$appml.display.value | The value of the data field about to be displayed. |
$appml.error.number | The error number. |
$appml.error.description | The error description. |