この章では、Web アプリケーションのプロトタイプを構築します。
まず、お好みの CSS を使用して、きちんとした HTML プロトタイプを作成します。
この例では、bootstrap 使用しています:
<!DOCTYPE html>
<html lang="ja">
<title>Customers</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<body>
<div class="container">
<h1>Customers</h1>
<table class="table table-striped
table-bordered">
<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>
Try It Yourself »
![]() |
{{ ... }} は、今後のデータのためのプレースホルダです。 |
|---|
HTML プロトタイプを作成した後は、AppML を追加することができます:
<!DOCTYPE html>
<html lang="ja">
<title>Customers</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="http://www.w3schools.com/appml/2.0.3/appml.js"></script>
<script src="http://www.w3schools.com/appml/2.0.3/appml_sql.js"></script>
<body>
<div class="container" appml-data="customers.js">
<h1>Customers</h1>
<table class="table table-striped
table-bordered">
<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>
Try It Yourself »
AppML を追加します:
<script src="http://www.w3schools.com/appml/2.0.3/appml.js">
ローカル WebSQL データベースを追加します:
<script src="http://www.w3schools.com/appml/2.0.3/appml_sql.js">
データソースを定義します:
appml-data="customers.js"
複数レコードの各レコードごとに繰り返されるべき HTML 要素を定義します:
appml_repeat="records"
![]() |
簡単にするため、データベースに接続する前に、 customers.js のようなローカルデータで開始します。 |
|---|
データベースを使用できるようにするには、AppML データベースモデルが必要です:
{
"rowsperpage" : 10,
"database" : {
"connection"
: "localmysql",
"sql" : "Select * from Customers",
"orderby"
: "CustomerName",
}
ローカル・データベースを持っていない場合は、Web SQL データベースを作成するための AppML モデルを使用することができます。
1 レコードを持つテーブルを作成するには、次のようなモデルを使用します: proto_customers_single.js.
![]() |
ローカルデータベースの作成は、IE や Firefox では動作しません。 Chrome か Safari を使用してください。 |
|---|
アプリケーションでモデルを使用してください。 データソースを local?model=proto_customers_single へ変更します:
<div appml-data="local?model=proto_customers_single">
<h1>Customers</h1>
<table class="table table-striped
table-bordered">
<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>
Try It Yourself »
複数のレコードを持つテーブルを作成するには、次のようなモデルを使用します: proto_customers_all.js.
データソースを local?model=proto_customers_all へ変更します:
<div appml-data="local?model=proto_customers_all">
<h1>Customers</h1>
<table class="table table-striped
table-bordered">
<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>
Try It Yourself »
すべてのアプリケーションに、共通のナビゲーションツールバーを設定するものとします:
そのための HTML テンプレートを作成します:
<div class="btn-group" role="toolbar" style="margin-bottom:10px;">
<button id='appmlbtn_first' type="button"
class="btn btn-default">
<span class="glyphicon
glyphicon-fast-backward"></span></button>
<button id='appmlbtn_previous'
type="button" class="btn btn-default">
<span class="glyphicon
glyphicon-backward"></span></button>
<button id='appmlbtn_text'
type="button" class="btn btn-default disabled"></button>
<button
id='appmlbtn_next' type="button" class="btn btn-default">
<span
class="glyphicon glyphicon-forward"></span></button>
<button id='appmlbtn_last' type="button" class="btn btn-default">
<span class="glyphicon glyphicon-fast-forward"></span></button>
<button id='appmlbtn_query' type="button"
class="btn btn-primary">
<span class="glyphicon
glyphicon-search"></span> Filter</button>
</div>
<div
id="appmlmessage"></div>
"inc_listcommands.htm" などの、適切な名前を持つファイルにテンプレートを保存します。
appml-include-html 属性を使用して、プロトタイプにテンプレートをインクルードします:
<div appml-data="local?model=proto_customers_all">
<h1>Customers</h1>
<div
appml-include-html="inc_listcommands.htm"></div>
<table
class="table table-striped table-bordered">
<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>
Try It Yourself »