رسائل 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 بالبيانات (جاهز للعرض) ، سيرسل رسالة " محملة ".
هذا هو المكان المثالي لتقديم التغييرات (إذا لزم الأمر) على البيانات المحملة.
مثال
function myController($appml) {
if ($appml.message == "loaded") {
// compute your values here before display
}
}
رسالة "عرض"
في كل مرة يعرض AppML عنصر بيانات ، سيرسل رسالة " عرض ".
هذا هو المكان المثالي لتعديل الإخراج:
مثال
<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 حرفًا ، ويتم تحويل "البلد" إلى الأحرف الكبيرة.
رسالة "تم"
عندما ينتهي تطبيق 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 رسالة " خطأ ".
هذا هو المكان المثالي للتعامل مع الأخطاء.
مثال
<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. |