AppML 数据文件

"data" 属性

"data" 属性将数据文件定义为数据源。它有以下 子属性:

元素描述
"type"数据文件的类型 ("csvfile", "xmlfile", 或者 "jsonfile")
"filename"文件名
"record"XML 数据节点的名称(如果是 xmlfile)
"items"数据项

文本文件中的数据

该模型从逗号分隔的文本文件中获取包含 Title、Artist 和 Price(作为项目 1、2 和 5)的记录:

模型
  1. {
  2. "data": {
  3. "type" : "csvfile",
  4. "filename": "cd_catalog.txt",
  5. "items" : [
  6. {"name": "Title", "index": 1},
  7. {"name": "Artist","index": 2},
  8. {"name": "Price", "index": 5}
  9. ]
  10. }
  11. }

完整代码:

  1. <!DOCTYPE html>
  2. <html>
  3. <link rel="stylesheet" href="https://cankaoshouce.com/css/w3.css">
  4. <script src="https://cankaoshouce.com/js/appml/appml.js"></script>
  5. <body>
  6. <div class="w3-container" appml-data="/example/appml/appml.aspx?model=/example/appml/model_cd_from_txt">
  7. <h2>CD Collection</h2>
  8. <h3>Extracted from a comma separated text file</h3>
  9. <div appml-include-html="/example/appml/inc_listcommands_nofilter.html"></div>
  10. <table class="w3-table-all">
  11. <tr>
  12. <th>Title</th>
  13. <th>Artist</th>
  14. <th>Price</th>
  15. </tr>
  16. <tr appml-repeat="records">
  17. <td>{{Title}}</td>
  18. <td>{{Artist}}</td>
  19. <td>{{Price}}</td>
  20. </tr>
  21. </table>
  22. </div>
  23. </body>
  24. </html>

来自 XML 文件的数据

该模型从 XML 文件中的 CD 节点获取包含 Title、Artist 和 Price 的记录:

模型
  1. {
  2. "data": {
  3. "type" : "xmlfile",
  4. "filename": "cd_catalog.xml",
  5. "record" : "CD",
  6. "items" : [
  7. {"name": "Artist", "nodename": "ARTIST"},
  8. {"name": "Title", "nodename": "TITLE"},
  9. {"name": "Country","nodename": "COUNTRY"}
  10. ]
  11. }
  12. }

完整代码:

  1. <!DOCTYPE html>
  2. <html>
  3. <link rel="stylesheet" href="https://cankaoshouce.com/css/w3.css">
  4. <script src="https://cankaoshouce.com/js/appml/appml.js"></script>
  5. <body>
  6. <div class="w3-container" appml-data="/example/appml/appml.aspx?model=/example/appml/model_cd_from_xml">
  7. <h2>CD Collection</h2>
  8. <h3>Extracted from a comma separated text file</h3>
  9. <div appml-include-html="/example/appml/inc_listcommands_nofilter.html"></div>
  10. <table class="w3-table-all">
  11. <tr>
  12. <th>Title</th>
  13. <th>Artist</th>
  14. <th>Country</th>
  15. </tr>
  16. <tr appml-repeat="records">
  17. <td>{{Title}}</td>
  18. <td>{{Artist}}</td>
  19. <td>{{Country}}</td>
  20. </tr>
  21. </table>
  22. </div>
  23. </body>
  24. </html>

来自 JSON 文件的数据

该模型从 JSON 文件中的 CD 对象数组中获取包含 Title、Artist 和 Price 的记录:

模型
  1. {
  2. "data" : {
  3. "type" : "jsonfile",
  4. "filename" : "cd_catalog.js",
  5. "record" : "cd",
  6. "items" : [
  7. {"name" : "Title", "nodename" : "title"},
  8. {"name" : "Artist", "nodename" : "artist"},
  9. {"name" : "Price", "nodename" : "price"}
  10. ]
  11. }
  12. }

完整代码:

  1. <!DOCTYPE html>
  2. <html>
  3. <link rel="stylesheet" href="https://cankaoshouce.com/css/w3.css">
  4. <script src="https://cankaoshouce.com/js/appml/appml.js"></script>
  5. <body>
  6. <div class="w3-container" appml-data="/example/appml/appml.aspx?model=/example/appml/model_cd_from_json">
  7. <h2>CD Collection</h2>
  8. <h3>Extracted from an XML file</h3>
  9. <div appml-include-html="/example/appml/inc_listcommands_nofilter.html"></div>
  10. <table class="w3-table-all">
  11. <tr>
  12. <th>Title</th>
  13. <th>Artist</th>
  14. <th>Price</th>
  15. </tr>
  16. <tr appml-repeat="records">
  17. <td>{{Title}}</td>
  18. <td>{{Artist}}</td>
  19. <td>{{Price}}</td>
  20. </tr>
  21. </table>
  22. </div>
  23. </body>
  24. </html>

分类导航