AppML 数据文件
"data" 属性
"data" 属性将数据文件定义为数据源。它有以下 子属性:
| 元素 | 描述 |
|---|---|
| "type" | 数据文件的类型 ("csvfile", "xmlfile", 或者 "jsonfile") |
| "filename" | 文件名 |
| "record" | XML 数据节点的名称(如果是 xmlfile) |
| "items" | 数据项 |
文本文件中的数据
该模型从逗号分隔的文本文件中获取包含 Title、Artist 和 Price(作为项目 1、2 和 5)的记录:
模型
{"data": {"type" : "csvfile","filename": "cd_catalog.txt","items" : [{"name": "Title", "index": 1},{"name": "Artist","index": 2},{"name": "Price", "index": 5}]}}
完整代码:
<!DOCTYPE html><html><link rel="stylesheet" href="https://cankaoshouce.com/css/w3.css"><script src="https://cankaoshouce.com/js/appml/appml.js"></script><body><div class="w3-container" appml-data="/example/appml/appml.aspx?model=/example/appml/model_cd_from_txt"><h2>CD Collection</h2><h3>Extracted from a comma separated text file</h3><div appml-include-html="/example/appml/inc_listcommands_nofilter.html"></div><table class="w3-table-all"><tr><th>Title</th><th>Artist</th><th>Price</th></tr><tr appml-repeat="records"><td>{{Title}}</td><td>{{Artist}}</td><td>{{Price}}</td></tr></table></div></body></html>
来自 XML 文件的数据
该模型从 XML 文件中的 CD 节点获取包含 Title、Artist 和 Price 的记录:
模型
{"data": {"type" : "xmlfile","filename": "cd_catalog.xml","record" : "CD","items" : [{"name": "Artist", "nodename": "ARTIST"},{"name": "Title", "nodename": "TITLE"},{"name": "Country","nodename": "COUNTRY"}]}}
完整代码:
<!DOCTYPE html><html><link rel="stylesheet" href="https://cankaoshouce.com/css/w3.css"><script src="https://cankaoshouce.com/js/appml/appml.js"></script><body><div class="w3-container" appml-data="/example/appml/appml.aspx?model=/example/appml/model_cd_from_xml"><h2>CD Collection</h2><h3>Extracted from a comma separated text file</h3><div appml-include-html="/example/appml/inc_listcommands_nofilter.html"></div><table class="w3-table-all"><tr><th>Title</th><th>Artist</th><th>Country</th></tr><tr appml-repeat="records"><td>{{Title}}</td><td>{{Artist}}</td><td>{{Country}}</td></tr></table></div></body></html>
来自 JSON 文件的数据
该模型从 JSON 文件中的 CD 对象数组中获取包含 Title、Artist 和 Price 的记录:
模型
{"data" : {"type" : "jsonfile","filename" : "cd_catalog.js","record" : "cd","items" : [{"name" : "Title", "nodename" : "title"},{"name" : "Artist", "nodename" : "artist"},{"name" : "Price", "nodename" : "price"}]}}
完整代码:
<!DOCTYPE html><html><link rel="stylesheet" href="https://cankaoshouce.com/css/w3.css"><script src="https://cankaoshouce.com/js/appml/appml.js"></script><body><div class="w3-container" appml-data="/example/appml/appml.aspx?model=/example/appml/model_cd_from_json"><h2>CD Collection</h2><h3>Extracted from an XML file</h3><div appml-include-html="/example/appml/inc_listcommands_nofilter.html"></div><table class="w3-table-all"><tr><th>Title</th><th>Artist</th><th>Price</th></tr><tr appml-repeat="records"><td>{{Title}}</td><td>{{Artist}}</td><td>{{Price}}</td></tr></table></div></body></html>