AppML-prototype
In dit hoofdstuk gaan we een prototype bouwen voor een webapplicatie.
Een HTML-prototype maken
Maak eerst een fatsoenlijk HTML-prototype met uw favoriete CSS.
In dit voorbeeld hebben we W3.CSS gebruikt:
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>
{{ ... }} Zijn tijdelijke aanduidingen voor toekomstige gegevens.
AppML toevoegen
Nadat u een HTML-prototype heeft gemaakt, kunt u AppML toevoegen:
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>
AppML toevoegen:
<script src="https://www.w3schools.com/appml/2.0.3/appml.js">
Voeg een lokale WebSQL-database toe:
<script src="https://www.w3schools.com/appml/2.0.3/appml_sql.js">
Definieer een gegevensbron:
appml-data="klanten.js"
Definieer het HTML-element dat moet worden herhaald voor elk record in records:
appml_repeat="records"
Om het eenvoudig te maken, begint u met lokale gegevens zoals voordat u verbinding maakt met een database.
Een AppML-model maken
Om een database te kunnen gebruiken, heeft u een AppML-databasemodel nodig:
proto_customers.js
{
"rowsperpage" : 10,
"database" : {
"connection"
: "localmysql",
"sql" : "Select * from Customers",
"orderby"
: "CustomerName",
}
Als u geen lokale database heeft, kunt u het AppML-model gebruiken om een Web SQL-database te maken.
Gebruik een model als dit om een tabel met één record te maken: .
Het maken van een lokale database werkt niet in IE of Firefox. Gebruik Chrome of Safari.
Gebruik het model in uw aanvraag. Wijzig de gegevensbron in 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>
Maak een lokale database met meerdere records
Gebruik een model als dit om een tabel met meerdere records te maken: .
Wijzig de gegevensbron in 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>
Een navigatiesjabloon toevoegen
Stel dat u wilt dat al uw toepassingen een gemeenschappelijke navigatiewerkbalk hebben:
Maak er een HTML-sjabloon voor:
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>
Sla de sjabloon op in een bestand met een eigennaam zoals "inc_listcommands.htm".
Neem de sjabloon op in uw prototype met het attribuut 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>