AppML 数据

AppML 的 主要 目的是为 HTML 页面提供 数据


将 AppML 连接到数据

  • AppML 可以显示来自变量的数据
  • AppML 可以显示文件中的数据
  • AppML 可以显示数据库中的数据

使用 JavaScript 对象的 AppML

分离 HTML 和数据的常用方法是将数据存储在 JavaScript 对象中。

实例
  1. <!DOCTYPE html>
  2. <html>
  3. <title>Customers</title>
  4. <link rel="stylesheet" href="/example/appml/style.css">
  5. <script src="https://cankaoshouce.com/js/appml/appml.js"></script>
  6. <body>
  7. <h2>Customers</h2>
  8. <table appml-data="dataObj">
  9. <tr>
  10. <th>Customer</th>
  11. <th>City</th>
  12. <th>Country</th>
  13. </tr>
  14. <tr appml-repeat="records">
  15. <td>{{CustomerName}}</td>
  16. <td>{{City}}</td>
  17. <td>{{Country}}</td>
  18. </tr>
  19. </table>
  20. <script>
  21. var dataObj = {
  22. "records":[
  23. {"CustomerName":"Alfreds Futterkiste","City":"Berlin","Country":"Germany"},
  24. {"CustomerName":"Ana Trujillo Emparedados y helados","City":"México D.F.","Country":"Mexico"},
  25. {"CustomerName":"Antonio Moreno Taquería","City":"México D.F.","Country":"Mexico"},
  26. {"CustomerName":"Around the Horn","City":"London","Country":"UK"},
  27. {"CustomerName":"B's Beverages","City":"London","Country":"UK"},
  28. {"CustomerName":"Berglunds snabbköp","City":"Luleå","Country":"Sweden"},
  29. {"CustomerName":"Blauer See Delikatessen","City":"Mannheim","Country":"Germany"},
  30. {"CustomerName":"Blondel père et fils","City":"Strasbourg","Country":"France"},
  31. {"CustomerName":"Bólido Comidas preparadas","City":"Madrid","Country":"Spain"},
  32. {"CustomerName":"Bon app'","City":"Marseille","Country":"France"},
  33. {"CustomerName":"Bottom-Dollar Marketse","City":"Tsawassen","Country":"Canada"},
  34. {"CustomerName":"Cactus Comidas para llevar","City":"Buenos Aires","Country":"Argentina"},
  35. {"CustomerName":"Centro comercial Moctezuma","City":"México D.F.","Country":"Mexico"},
  36. {"CustomerName":"Chop-suey Chinese","City":"Bern","Country":"Switzerland"},
  37. {"CustomerName":"Comércio Mineiro","City":"São Paulo","Country":"Brazil"}
  38. ]};
  39. </script>
  40. </body>
  41. </html>

使用 JSON 文件的 AppML

另一种分离 HTML 和数据的常用方法是将数据存储在 JSON 文件中:

customers.js
  1. {
  2. "records":[
  3. {"CustomerName":"Alfreds Futterkiste","City":"Berlin","Country":"Germany"},
  4. {"CustomerName":"Ana Trujillo Emparedados y helados","City":"México D.F.","Country":"Mexico"},
  5. {"CustomerName":"Antonio Moreno Taquería","City":"México D.F.","Country":"Mexico"},
  6. {"CustomerName":"Around the Horn","City":"London","Country":"UK"},
  7. {"CustomerName":"B's Beverages","City":"London","Country":"UK"},
  8. {"CustomerName":"Berglunds snabbköp","City":"Luleå","Country":"Sweden"},
  9. {"CustomerName":"Blauer See Delikatessen","City":"Mannheim","Country":"Germany"},
  10. {"CustomerName":"Blondel père et fils","City":"Strasbourg","Country":"France"},
  11. {"CustomerName":"Bólido Comidas preparadas","City":"Madrid","Country":"Spain"},
  12. {"CustomerName":"Bon app'","City":"Marseille","Country":"France"},
  13. {"CustomerName":"Bottom-Dollar Marketse","City":"Tsawassen","Country":"Canada"},
  14. {"CustomerName":"Cactus Comidas para llevar","City":"Buenos Aires","Country":"Argentina"},
  15. {"CustomerName":"Centro comercial Moctezuma","City":"México D.F.","Country":"Mexico"},
  16. {"CustomerName":"Chop-suey Chinese","City":"Bern","Country":"Switzerland"},
  17. {"CustomerName":"Comércio Mineiro","City":"São Paulo","Country":"Brazil"}
  18. ]
  19. }

使用 AppML,可以在 AppML 数据属性中指定 JSON 文件作为数据源:

实例
  1. <!DOCTYPE html>
  2. <html lang="en-US">
  3. <title>Customers</title>
  4. <link rel="stylesheet" href="/example/appml/style.css">
  5. <script src="https://cankaoshouce.com/js/appml/appml.js"></script>
  6. <body>
  7. <h2>Customers</h2>
  8. <div appml-data="/example/appml/customers.js">
  9. <table>
  10. <tr>
  11. <th>Customer</th>
  12. <th>City</th>
  13. <th>Country</th>
  14. </tr>
  15. <tr appml-repeat="records">
  16. <td>{{CustomerName}}</td>
  17. <td>{{City}}</td>
  18. <td>{{Country}}</td>
  19. </tr>
  20. </table>
  21. </div>
  22. </body>
  23. </html>

使用数据库的 AppML

在 web 服务器的帮助下,您可以向应用程序提供SQL数据。

本例使用 ASPX 从 MySQL 数据库读取数据:

实例
  1. <!DOCTYPE html>
  2. <html>
  3. <title>Customers</title>
  4. <link rel="stylesheet" href="/example/appml/style.css">
  5. <script src="https://cankaoshouce.com/js/appml/appml.js"></script>
  6. <body>
  7. <h2>Customers</h2>
  8. <table appml-data="/example/appml/customers.ashx">
  9. <tr>
  10. <th>Customer</th>
  11. <th>City</th>
  12. <th>Country</th>
  13. </tr>
  14. <tr appml-repeat="records">
  15. <td>{{CustomerName}}</td>
  16. <td>{{City}}</td>
  17. <td>{{Country}}</td>
  18. </tr>
  19. </table>
  20. </body>
  21. </html>

AppML 的强大功能

您即将发现 AppML 的强大功能。

AppML 可以为您提供以下数据、控制器和模型:

  • 超简单的 HTML 应用程序开发
  • 超级简单的建模、原型制作和测试

您可以在 HTML 页面中放入任意数量的 AppML 应用程序。

AppML 不会干扰页面的其他部分。

您可以完全自由地使用 HTML、CSS 和 JavaScript。

AppML 可以完全用于开发 CRUD web 应用程序。

CRUD: Create(创建), Read(读取), Update(更新), Delete(删除)。