Dữ liệu AppML
Mục đích chính của AppML là cung cấp dữ liệu cho các trang HTML.
Kết nối AppML với dữ liệu
- AppML có thể hiển thị dữ liệu từ các biến
- AppML có thể hiển thị dữ liệu từ các tệp
- AppML có thể hiển thị dữ liệu từ cơ sở dữ liệu
AppML Sử dụng Đối tượng JavaScript
Một cách phổ biến để tách HTML và Dữ liệu, là lưu trữ dữ liệu trong một đối tượng JavaScript.
Thí dụ
<table appml-data="dataObj">
<tr>
<th>Customer</th>
<th>City</th>
<th>Country</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 Sử dụng tệp JSON
Một cách phổ biến khác để tách HTML và Dữ liệu, là lưu trữ dữ liệu trong tệp JSON:
khách hàng.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"}
]
}
Với AppML, bạn có thể chỉ định tệp JSON làm nguồn dữ liệu trong thuộc tính appml-data:
Thí dụ
<table appml-data="customers.js">
<tr>
<th>Customer</th>
<th>City</th>
<th>Country</th>
</tr>
<tr appml-repeat="records">
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
AppML Sử dụng Cơ sở dữ liệu
Với một chút trợ giúp từ máy chủ web, bạn có thể cung cấp dữ liệu SQL cho ứng dụng của mình.
Ví dụ này sử dụng PHP để đọc dữ liệu từ cơ sở dữ liệu MySQL:
Thí dụ
<table appml-data="https://www.w3schools.com/appml/customers.php">
<tr>
<th>Customer</th>
<th>City</th>
<th>Country</th>
</tr>
<tr appml-repeat="records">
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
Sức mạnh của AppML
Bạn sắp khám phá sức mạnh của AppML.
AppML có thể cung cấp cho bạn dữ liệu, bộ điều khiển và mô hình cho:
- Phát triển ứng dụng HTML siêu dễ dàng
- Tạo mô hình, tạo mẫu và thử nghiệm siêu dễ dàng
Bạn có thể đặt bao nhiêu ứng dụng AppML tùy thích vào trong một trang HTML.
AppML không can thiệp vào các phần khác của trang.
Bạn có toàn quyền sử dụng HTML, CSS và JavaScript.
AppML có thể được sử dụng để phát triển các ứng dụng web CRUD quy mô đầy đủ.
CRUD: C reate, R ead, U pdate, D elete.
Để khám phá sức mạnh của AppML: Xem Bản trình diễn AppML .