AppML 메시지
AppML 메시지 및 작업
AppML이 작업을 수행하려고 하면 응용 프로그램 개체($appml)를 컨트롤러에 보냅니다.
응용 프로그램 개체의 속성 중 하나는 응용 프로그램 상태를 설명하는 메시지($appml.message)입니다.
이 메시지를 테스트하면 작업에 따라 고유한 JavaScript 코드를 추가할 수 있습니다.
예시
function myController($appml) {
if ($appml.message == "ready") {alert ("Hello
Application");}
}
AppML 메시지
다음은 수신할 수 있는 AppML 메시지 목록입니다.
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. |
"준비" 메시지
AppML 애플리케이션이 데이터를 로드할 준비가 되면 "준비" 메시지를 보냅니다.
이것은 애플리케이션에 초기 데이터(시작 값)를 제공하기에 완벽한 장소입니다.
예시
<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>
위의 예에서 $appml.message 가 "준비"되면 컨트롤러는 애플리케이션에 두 개의 새 속성( 오늘 및 저작권 )을 추가합니다.
응용 프로그램이 실행되면 응용 프로그램에서 새 속성을 사용할 수 있습니다.
"로드됨" 메시지
AppML 애플리케이션이 데이터와 함께 로드되면(표시할 준비가 됨) " loaded " 메시지를 보냅니다.
이것은 로드된 데이터에 변경 사항(필요한 경우)을 제공하기에 완벽한 장소입니다.
예시
function myController($appml) {
if ($appml.message == "loaded") {
// compute your values here before display
}
}
"디스플레이" 메시지
AppML이 데이터 항목을 표시할 때마다 " display " 메시지를 보냅니다.
이것은 출력을 수정하기에 완벽한 장소입니다:
예시
<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>
위의 예에서 "CustomerName"은 15자로 잘리고 "Country"는 대문자로 변환됩니다.
"완료" 메시지
AppML 애플리케이션이 데이터 표시를 마치면 " 완료 " 메시지를 보냅니다.
이것은 (표시 후) 애플리케이션 데이터를 정리하거나 계산하기에 완벽한 장소입니다.
예시
<script>
function myController($appml) {
if ($appml.message == "done") {
calculate data here
}
}
</script>
"제출" 메시지
AppML 애플리케이션이 데이터를 제출할 준비가 되면 " 제출 " 메시지를 보냅니다.
이것은 애플리케이션 입력을 검증하기에 완벽한 장소입니다.
예시
<script>
function myController($appml) {
if ($appml.message == "submit") {
validate data here
}
}
</script>
"오류" 메시지
오류가 발생하면 AppML은 " error " 메시지를 보냅니다.
이것은 오류를 처리하기에 완벽한 장소입니다.
예시
<script>
function myController($appml) {
if ($appml.message ==
"error") {
alert ($appml.error.number + " " + $appml.error.description)
}
}
</script>
AppML 속성
다음은 일반적으로 사용되는 몇 가지 AppML 속성 목록입니다.
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. |