AppML教程

AppML 环境

AppML 的使用非常简单。只需在 HTML 页面中使用 <script> 标记引用 JavaScript 文件并部署在 Web 服务器上。
Web Server-PHP 可以与几乎所有的 Web 服务器软件一起使用,包括 Microsoft 的 Internet Information Server (IIS),但最常用的是 Apache Server。在此处免费下载 Apache-https://httpd.apache.org/download.cgi
appml.js 可以通过以下方式访问-
您可以从其官方网站下载appml.js
现在引用文件,如以下代码所示。
<script type = 'text/javascript' src = 'appml.js'></script>
更新 src 属性以匹配下载文件的保存位置。
您可以直接从 W3Schools 引用 appml.js 库-
<script src = "https://www.w3schools.com/appml/2.0.3/appml.js" 
   type = "text/javascript"></script>
注意-在本教程的所有章节中,我们都提到了 AppML 库的 W3Schools 版本。

示例

AppML 基于模型-视图-控制器 (MVC) 模式。我们来看一个简单的 AppML 示例。
<!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>
   <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>
以下行指的是 AppML 库。
<script src = "https://www.w3schools.com/appml/2.0.3/appml.js" 
   type = "text/javascript"> </script>
这一行引用了 AppML 库。
我们在表中添加了一个属性 app-data 来引用学生对象。可以是json、txt、xml甚至是数据库模型。
<p>First String: < input data-bind = "value: firstString" /> </p>
这就是我们如何使用 body 部分中的 'appml-data' 属性将 ViewModel 中的值绑定到 HTML 元素。

输出

将上述代码另存为 my_first_appml_program.html。将文件部署在 Web 服务器上并访问该文件。验证输出。
第一个示例

下载 appml.php

从 W3Schools 下载文件 https://www.w3schools.com/appml/2.0.3/appml.php.txt 将文件复制到您的网站并将其重命名为 appml.php。它将用于在接下来的示例中加载 appml 模型。

appml_config.php

使用以下内容创建 appml_config.php。
<?php echo("Access Forbidden");exit();?>
{
"dateformat" : "yyyy-mm-dd"
}
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4