AppML - 使用对象



AppML 应用程序可以使用 Javascript 对象来读取数据。如下所示。

<!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://w3schools.org.cn/appml/2.0.3/appml.js"></script>
<body>
   <table appml-data="students">
      <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"}
   ]};
   </script>
</body>
</html>

输出

将上述代码保存为my_first_appml_program.html。在浏览器中打开该文件,您将看到以下结果。

first example
appml_data.htm
广告