Prototipe AppML


Dalam bab ini, kita akan membangun sebuah prototipe untuk aplikasi web.


Buat Prototipe HTML

Pertama, buat prototipe HTML yang layak , menggunakan CSS favorit Anda.

Kami telah menggunakan W3.CSS dalam contoh ini:

Contoh

<!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>

{{ ... }} Adalah penampung untuk data di masa mendatang.


Tambahkan AppML

Setelah Anda membuat prototipe HTML, Anda dapat menambahkan AppML:

Contoh

<!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>

Tambahkan AppML:

<script src="https://www.w3schools.com/appml/2.0.3/appml.js">

Tambahkan database WebSQL lokal:

<script src="https://www.w3schools.com/appml/2.0.3/appml_sql.js">

Tentukan sumber data:

appml-data="pelanggan.js"

Tentukan elemen HTML yang akan diulang untuk setiap record dalam record:

appml_repeat="catatan"

Untuk membuatnya sederhana, mulailah dengan data lokal seperti sebelum menghubungkan ke database.


Buat Model AppML

Untuk dapat menggunakan database, Anda memerlukan model database AppML:

proto_customers.js

{
"rowsperpage" : 10,
"database" : {
"connection" : "localmysql",
"sql" : "Select * from Customers",
"orderby" : "CustomerName",
}

Jika Anda tidak memiliki database lokal, Anda dapat menggunakan model AppML untuk membuat database SQL Web.

Untuk membuat tabel dengan satu record, gunakan model seperti ini: .

Membuat database lokal tidak berfungsi di IE atau Firefox. Gunakan Chrome atau Safari.

Gunakan model dalam aplikasi Anda. Ubah sumber data menjadi local?model=proto_customers_single :

Contoh

<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>

Buat Database Lokal dengan Banyak Catatan

Untuk membuat tabel dengan banyak record, gunakan model seperti ini: .

Ubah sumber data menjadi lokal?model=proto_customers_all

Contoh

<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>

Tambahkan Template Navigasi

Misalkan Anda ingin semua aplikasi Anda memiliki bilah alat navigasi umum:

Buat template HTML untuk itu:

inc_listcommands.htm

<div class="w3-bar w3-border w3-section">
<button class="w3-button" id='appmlbtn_first'>&#10094;&#10094;</button>
<button class="w3-button" id='appmlbtn_previous'>&#10094;</button>
<button class="w3-button w3-hover-none" id='appmlbtn_text'></button>
<button class="w3-button" id='appmlbtn_next'>&#10095;</button>
<button class="w3-button" id='appmlbtn_last'>&#10095;&#10095;</button>
<button class="w3-btn ws-green" id='appmlbtn_query'>Filter</button>
</div>

<div id="appmlmessage"></div>

Simpan template dalam file dengan nama yang tepat seperti "inc_listcommands.htm".

Sertakan template dalam prototipe Anda dengan atribut appml-include-html :

Contoh

<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>