English 中文(简体)
AppML - Controller
  • 时间:2024-12-22

AppML - Controller


Previous Page Next Page  

AppML apppcation allows to control the UI using the controller function. appml-controller tag provides the name of the javascript function which acts as a controller. AppML apppcation may or may not have a controller.

Syntax


<table appml-controller="studentController"></table>

AppML sends messages to controller function via an apppcation object denoted by $appml. Based on the properties of $appml we can perform various types of operations on HTML content. Following are some of the important examples.

    Initiapze data

    Update apppcation data

    Input/output handpng

    Data vapdation

    Data summarization

    Error handpng

    Apppcation start/stop

Example

student_apppcation.html


<!DOCTYPE html>
<html lang="en-US">
   <title>Students</title>
   <style>	  
      table {
         border-collapse: collapse;
         width: 100%;
      }

      th, td {
         text-apgn: 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":"Jupe","class":"12","section":"White"},
            {"studentName":"Ap","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>

Output

Deploy the apppcation on Web Server and access the html page. Verify the output.

first apppcation Advertisements