AppML Denetleyicileri


AppML denetleyicisinin amacı, uygulamanızı kontrol etmenize izin vermektir .


Bir Kontrolör Ne Yapabilir?

  • Başlangıç ​​verilerini ayarla
  • Uygulama verilerini değiştir
  • Giriş ve çıkışı yönet
  • Verileri doğrula
  • Verileri özetle
  • Hataları işleme
  • Uygulamaları başlat ve durdur
  • Ve daha fazlası

Denetleyici Olmadan

Varsayılan olarak AppML uygulamaları bir denetleyici olmadan çalışır:

Örnek

<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>

Denetleyici ile

Bir AppML denetleyicisi ile uygulamanızı JavaScript ile kontrol edebilirsiniz .

Denetleyici, sizin tarafınızdan sağlanan bir JavaScript işlevidir .

appml -controller niteliği, bir denetleyici işlevine atıfta bulunmak için kullanılır.

Örnek

<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>

Yukarıdaki örnekteki denetleyici (myController), görüntülenmeden önce "CustomerName" değerini büyük harfe değiştirir.

Bir denetleyiciniz varsa, AppML her önemli eylem için uygulama nesnesini ($appml) denetleyiciye gönderir.

Uygulama özelliklerinden biri, uygulama durumunu açıklayan bir mesajdır ($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.

Mesajlar bir sonraki bölümde açıklanmıştır.