AppML prototipe
In hierdie hoofstuk sal ons 'n prototipe vir 'n webtoepassing bou.
Skep 'n HTML-prototipe
Skep eers 'n ordentlike HTML-prototipe met jou gunsteling CSS.
Ons het W3.CSS in hierdie voorbeeld gebruik:
Voorbeeld
<!DOCTYPE html>
<html lang="en-US">
<title>Customers</title>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>
<div class="w3-container">
<h1>Customers</h1>
<table class="w3-table-all">
<tr>
<th>Customer</th>
<th>City</th>
<th>Country</th>
</tr>
<tr>
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
</div>
</body>
</html>
{{ ... }} Is plekhouers vir toekomstige data.
Voeg AppML by
Nadat jy 'n HTML-prototipe geskep het, kan jy AppML byvoeg:
Voorbeeld
<!DOCTYPE html>
<html lang="en-US">
<title>Customers</title>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<script src="https://www.w3schools.com/appml/2.0.3/appml.js"></script>
<script src="https://www.w3schools.com/appml/2.0.3/appml_sql.js"></script>
<body>
<div class="w3-container" appml-data="customers.js">
<h1>Customers</h1>
<table class="w3-table-all">
<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>
</div>
</body>
</html>
Voeg AppML by:
<script src="https://www.w3schools.com/appml/2.0.3/appml.js">
Voeg 'n plaaslike WebSQL-databasis by:
<script src="https://www.w3schools.com/appml/2.0.3/appml_sql.js">
Definieer 'n databron:
appml-data="customers.js"
Definieer die HTML-element wat herhaal moet word vir elke rekord in rekords:
appml_repeat="rekords"
Om dit eenvoudig te maak, begin met plaaslike data soos voordat jy aan 'n databasis koppel.
Skep 'n AppML-model
Om 'n databasis te kan gebruik, sal jy 'n AppML databasismodel benodig:
proto_customers.js
{
"rowsperpage" : 10,
"database" : {
"connection"
: "localmysql",
"sql" : "Select * from Customers",
"orderby"
: "CustomerName",
}
As jy nie 'n plaaslike databasis het nie, kan jy die AppML-model gebruik om 'n Web SQL-databasis te skep.
Om 'n tabel met 'n enkele rekord te skep, gebruik 'n model soos hierdie: .
Die skep van 'n plaaslike databasis werk nie in IE of Firefox nie. Gebruik Chrome of Safari.
Gebruik die model in jou aansoek. Verander die databron na local?model=proto_customers_single :
Voorbeeld
<div class="w3-container" appml-data="local?model=proto_customers_single">
<h1>Customers</h1>
<table class="w3-table-all">
<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>
</div>
Skep 'n plaaslike databasis met veelvuldige rekords
Om 'n tabel met veelvuldige rekords te skep, gebruik 'n model soos hierdie: .
Verander die databron na local?model=proto_customers_all
Voorbeeld
<div class="w3-container" appml-data="local?model=proto_customers_all">
<h1>Customers</h1>
<table class="w3-table-all">
<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>
</div>
Voeg 'n navigasie-sjabloon by
Gestel jy wil hê dat al jou toepassings 'n gemeenskaplike navigasienutsbalk moet hê:
Skep 'n HTML-sjabloon daarvoor:
inc_listcommands.htm
<div class="w3-bar w3-border w3-section">
<button class="w3-button" id='appmlbtn_first'>❮❮</button>
<button class="w3-button" id='appmlbtn_previous'>❮</button>
<button class="w3-button w3-hover-none" id='appmlbtn_text'></button>
<button class="w3-button" id='appmlbtn_next'>❯</button>
<button class="w3-button" id='appmlbtn_last'>❯❯</button>
<button class="w3-btn ws-green" id='appmlbtn_query'>Filter</button>
</div>
<div id="appmlmessage"></div>
Stoor die sjabloon in 'n lêer met 'n eienaam soos "inc_listcommands.htm".
Sluit die sjabloon in jou prototipe in met die kenmerk appml-include-html :
Voorbeeld
<div class="w3-container" appml-data="local?model=proto_customers_all">
<h1>Customers</h1>
<div appml-include-html="inc_listcommands.htm"></div>
<table class="w3-table-all">
<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>
</div>