AppMLプロトタイプ


この章では、Webアプリケーションのプロトタイプを作成します。


HTMLプロトタイプを作成する

まず、お気に入りのCSSを使用して、適切なHTMLプロトタイプを作成します。

この例では、W3.CSSを使用しました。

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

{{...}}は将来のデータのプレースホルダーです。


AppMLを追加する

HTMLプロトタイプを作成したら、AppMLを追加できます。

<!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を追加します。

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

ローカルWebSQLデータベースを追加します。

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

データソースを定義します。

appml-data = "customers.js"

レコード内のレコードごとに繰り返されるHTML要素を定義します。

appml_repeat = "records"

簡単にするために、データベースに接続する前に、


AppMLモデルを作成する

データベースを使用できるようにするには、AppMLデータベースモデルが必要です。

proto_customers.js

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

ローカルデータベースがない場合は、AppMLモデルを使用してWebSQLデータベースを作成できます。

単一のレコードを持つテーブルを作成するには、のようなモデルを使用します。

ローカルデータベースの作成は、IEまたはFirefoxでは機能しません。ChromeまたはSafariを使用します。

アプリケーションでモデルを使用します。データソースをlocal?model = proto_customers_singleに変更します:

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

複数のレコードを持つローカルデータベースを作成する

複数のレコードを含むテーブルを作成するには、のようなモデルを使用します。

データソースをlocal?model = proto_customers_allに変更します

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

ナビゲーションテンプレートを追加する

すべてのアプリケーションに共通のナビゲーションツールバーを持たせたいとします。

そのためのHTMLテンプレートを作成します。

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>

テンプレートを「inc_listcommands.htm」のような適切な名前のファイルに保存します。

属性appml-include-htmlを使用してプロトタイプにテンプレートを含めます。

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