AppML - 控制器
AppML 应用程序允许使用控制器功能来控制 UI。appml-controller 标签提供充当控制器的 javascript 函数的名称。AppML 应用程序可能有也可能没有控制器。
句法
<table appml-controller="studentController"></table>
AppML 通过 $appml 表示的应用程序对象向控制器功能发送消息。基于 $appml 的属性,我们可以对 HTML 内容执行各种类型的操作。以下是一些重要的例子。
初始化数据
更新应用程序数据
输入/输出处理
数据验证
数据汇总
错误处理
应用程序启动/停止
例子
学生申请.html
<!DOCTYPE html>
<html lang="en-US">
   <title>Students</title>
   <style>	  
      table {
         border-collapse: collapse;
         width: 100%;
      }
      th, td {
         text-align: left;
         padding: 8px;
      }
      tr:nth-child(even) {background-color: #f2f2f2;}
   </style>
   <script src="https://www.w3schools.com/appml/2.0.3/appml.js"></script>
<body>
   <h1>Students</h1>
   <table appml-data="students" appml-controller="studentController">
      <tr>
         <th>Student</th>
         <th>Class</th>
         <th>Section</th>
      </tr>
      <tr appml-repeat="records">
         <td>{{studentName}}</td>
         <td>{{class}}</td>
         <td>{{section}}</td>
      </tr>
   </table>
   <script>
      var students = {
         "records":[
            {"studentName":"Ramesh","class":"12","section":"White"},
            {"studentName":"Suresh","class":"12","section":"Red"},
            {"studentName":"Mohan","class":"12","section":"Red"},
            {"studentName":"Robert","class":"12","section":"Red"},
            {"studentName":"Julie","class":"12","section":"White"},
            {"studentName":"Ali","class":"12","section":"White"},
            {"studentName":"Harjeet","class":"12","section":"White"}
         ]};
      function studentController($appml) {
         if ($appml.message == "display") {
            if ($appml.display.name == "studentName") {
               $appml.display.value = $appml.display.value.toUpperCase();
            }
         }
      }
   </script>
</body>
</html>
输出
在Web Server上部署应用程序并访问html页面。验证输出。
