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>

위의 예에서 컨트롤러(myController)는 표시되기 전에 "CustomerName" 값을 대문자로 변경합니다.

컨트롤러가 있는 경우 AppML은 모든 중요한 작업에 대해 응용 프로그램 개체 ($appml)를 컨트롤러로 보냅니다.

애플리케이션 속성 중 하나는 애플리케이션 상태를 설명하는 메시지($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.

메시지는 다음 장에서 설명합니다.