AppML-Prototyp
In diesem Kapitel werden wir einen Prototyp für eine Webanwendung erstellen.
Erstellen Sie einen HTML-Prototyp
Erstellen Sie zunächst einen anständigen HTML-Prototyp mit Ihrem bevorzugten CSS.
In diesem Beispiel haben wir W3.CSS verwendet:
Beispiel
<!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>
{{ ... }} Sind Platzhalter für zukünftige Daten.
Fügen Sie AppML hinzu
Nachdem Sie einen HTML-Prototyp erstellt haben, können Sie AppML hinzufügen:
Beispiel
<!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 hinzufügen:
<script src="https://www.w3schools.com/appml/2.0.3/appml.js">
Fügen Sie eine lokale WebSQL-Datenbank hinzu:
<script src="https://www.w3schools.com/appml/2.0.3/appml_sql.js">
Definieren Sie eine Datenquelle:
appml-data="customers.js"
Definieren Sie das HTML-Element, das für jeden Datensatz in Datensätzen wiederholt werden soll:
appml_repeat="Aufzeichnungen"
Beginnen Sie der Einfachheit halber mit lokalen Daten wie , bevor Sie eine Verbindung zu einer Datenbank herstellen.
Erstellen Sie ein AppML-Modell
Um eine Datenbank verwenden zu können, benötigen Sie ein AppML-Datenbankmodell:
proto_customers.js
{
"rowsperpage" : 10,
"database" : {
"connection"
: "localmysql",
"sql" : "Select * from Customers",
"orderby"
: "CustomerName",
}
Wenn Sie keine lokale Datenbank haben, können Sie das AppML-Modell verwenden, um eine Web-SQL-Datenbank zu erstellen.
Um eine Tabelle mit einem einzelnen Datensatz zu erstellen, verwenden Sie ein Modell wie dieses: .
Das Erstellen einer lokalen Datenbank funktioniert nicht in IE oder Firefox. Verwenden Sie Chrome oder Safari.
Verwenden Sie das Modell in Ihrer Anwendung. Ändern Sie die Datenquelle in local?model=proto_customers_single :
Beispiel
<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>
Erstellen Sie eine lokale Datenbank mit mehreren Datensätzen
Um eine Tabelle mit mehreren Datensätzen zu erstellen, verwenden Sie ein Modell wie dieses: .
Ändern Sie die Datenquelle in local?model=proto_customers_all
Beispiel
<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>
Fügen Sie eine Navigationsvorlage hinzu
Angenommen, Sie möchten, dass alle Ihre Anwendungen eine gemeinsame Navigationssymbolleiste haben:
Erstellen Sie dafür eine HTML-Vorlage:
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>
Speichern Sie die Vorlage in einer Datei mit einem richtigen Namen wie "inc_listcommands.htm".
Binden Sie die Vorlage mit dem Attribut appml-include-html in Ihren Prototyp ein :
Beispiel
<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>