AppML 資料
AppML 的 **主要** 目的在於為 HTML 頁面提供 **資料**。
連線 AppML 到資料
- AppML 可以顯示來自變數的資料
- AppML 可以顯示來自檔案的資料
- AppML 可以顯示來自資料庫的資料
AppML 使用 JavaScript 物件
分離 HTML 和資料的一種常見方法是將資料儲存在 JavaScript 物件中。
示例
<table appml-data="dataObj">
<tr>
<th>客戶</th>
<th>城市</th>
<th>國家</th>
</tr>
<tr appml-repeat="records">
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
<script>
var dataObj = {
"records":[
{"CustomerName":"Alfreds Futterkiste","City":"Berlin","Country":"Germany"},
{"CustomerName":"Ana Trujillo Emparedados y helados","City":"México D.F.","Country":"Mexico"},
{"CustomerName":"Antonio Moreno Taquería","City":"México D.F.","Country":"Mexico"},
{"CustomerName":"Around the Horn","City":"London","Country":"UK"},
{"CustomerName":"B's Beverages","City":"London","Country":"UK"},
{"CustomerName":"Berglunds snabbköp","City":"Luleå","Country":"Sweden"},
{"CustomerName":"Blauer See Delikatessen","City":"Mannheim","Country":"Germany"},
{"CustomerName":"Blondel père et fils","City":"Strasbourg","Country":"France"},
{"CustomerName":"Bólido Comidas preparadas","City":"Madrid","Country":"Spain"},
{"CustomerName":"Bon app'","City":"Marseille","Country":"France"},
{"CustomerName":"Bottom-Dollar Marketse","City":"Tsawassen","Country":"Canada"},
{"CustomerName":"Cactus Comidas para llevar","City":"Buenos Aires","Country":"Argentina"},
{"CustomerName":"Centro comercial Moctezuma","City":"México D.F.","Country":"Mexico"},
{"CustomerName":"Chop-suey Chinese","City":"Bern","Country":"Switzerland"},
{"CustomerName":"Comércio Mineiro","City":"São Paulo","Country":"Brazil"}
]};
</script>
自己試試 »
AppML 使用 JSON 檔案
另一種分離 HTML 和資料的方法是將資料儲存在 JSON 檔案中。
customers.js
{
"records":[
{"CustomerName":"Alfreds Futterkiste","City":"Berlin","Country":"Germany"},
{"CustomerName":"Ana Trujillo Emparedados y helados","City":"México D.F.","Country":"Mexico"},
{"CustomerName":"Antonio Moreno Taquería","City":"México D.F.","Country":"Mexico"},
{"CustomerName":"Around the Horn","City":"London","Country":"UK"},
{"CustomerName":"B's Beverages","City":"London","Country":"UK"},
{"CustomerName":"Berglunds snabbköp","City":"Luleå","Country":"Sweden"},
{"CustomerName":"Blauer See Delikatessen","City":"Mannheim","Country":"Germany"},
{"CustomerName":"Blondel père et fils","City":"Strasbourg","Country":"France"},
{"CustomerName":"Bólido Comidas preparadas","City":"Madrid","Country":"Spain"},
{"CustomerName":"Bon app'","City":"Marseille","Country":"France"},
{"CustomerName":"Bottom-Dollar Marketse","City":"Tsawassen","Country":"Canada"},
{"CustomerName":"Cactus Comidas para llevar","City":"Buenos Aires","Country":"Argentina"},
{"CustomerName":"Centro comercial Moctezuma","City":"México D.F.","Country":"Mexico"},
{"CustomerName":"Chop-suey Chinese","City":"Bern","Country":"Switzerland"},
{"CustomerName":"Comércio Mineiro","City":"São Paulo","Country":"Brazil"}
]
}
使用 AppML,您可以在 appml-data 屬性中將 JSON 檔案指定為資料來源。
示例
<table appml-data="customers.js">
<tr>
<th>客戶</th>
<th>城市</th>
<th>國家</th>
</tr>
<tr appml-repeat="records">
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
自己試試 »
AppML 使用資料庫
藉助一點 Web 伺服器的幫助,您可以為您的應用程式提供 SQL 資料。
此示例使用 PHP 從 MySQL 資料庫讀取資料。
示例
<table appml-data="https://w3schools.tw/appml/customers.php">
<tr>
<th>客戶</th>
<th>城市</th>
<th>國家</th>
</tr>
<tr appml-repeat="records">
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
自己試試 »
AppML 的強大功能
您即將發現 AppML 的強大功能。
AppML 可以為您提供用於
- 超級簡單的 HTML 應用程式開發
- 超級簡單的建模、原型設計和測試
您可以在一個 HTML 頁面中放入任意多個 AppML 應用程式。
AppML 不會干擾頁面的其他部分。
您擁有完全的 HTML、CSS 和 JavaScript 自由。
AppML 可用於開發全規模的 CRUD Web 應用程式。
CRUD:Create(建立)、Read(讀取)、Update(更新)、Delete(刪除)。
要發現 AppML 的強大功能:檢視 AppML 演示。