選單
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

AppML 原型


在本章中,我們將為 Web 應用程式構建一個原型。


建立 HTML 原型

首先,使用您喜歡的 CSS 建立一個不錯的 **HTML 原型**。

我們在本示例中使用了 W3.CSS

示例

<!DOCTYPE html>
<html lang="en-US">

<title>客戶</title>
<link rel="stylesheet" href="https://w3schools.tw/w3css/4/w3.css">

<body>

<div class="w3-container">
<h1>客戶</h1>
<table class="w3-table-all">
  <tr>
    <th>客戶</th>
    <th>城市</th>
    <th>國家</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>客戶</title>
<link rel="stylesheet" href="https://w3schools.tw/w3css/4/w3.css">
<script src="https://w3schools.tw/appml/2.0.3/appml.js"></script>
<script src="https://w3schools.tw/appml/2.0.3/appml_sql.js"></script>
<body>

<div class="w3-container" appml-data="customers.js">
<h1>客戶</h1>
<table class="w3-table-all">
  <tr>
    <th>客戶</th>
    <th>城市</th>
    <th>國家</th>
  </tr>
  <tr appml-repeat="records">
    <td>{{CustomerName}}</td>
    <td>{{City}}</td>
    <td>{{Country}}</td>
  </tr>
</table>
</div>

</body>
</html>
自己試試 »

新增 AppML

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

新增本地 WebSQL 資料庫

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

定義資料來源

appml-data="customers.js"

定義要為 records 中的每個記錄重複的 HTML 元素

appml_repeat="records"

為了簡單起見,先從本地資料開始,例如 ** customers.js**,然後再連線到資料庫。



建立 AppML 模型

要能夠使用資料庫,您需要一個 AppML 資料庫模型

proto_customers.js

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

如果您沒有本地資料庫,可以使用 AppML 模型建立一個 Web SQL 資料庫。

要建立包含單個記錄的表,請使用類似這樣的模型:**proto_customers_single.js**。

在 IE 或 Firefox 中建立本地資料庫不起作用。請使用 Chrome 或 Safari。

在您的應用程式中使用該模型。將資料來源更改為 **local?model=proto_customers_single**

示例

<div class="w3-container" appml-data="local?model=proto_customers_single">
<h1>客戶</h1>
<table class="w3-table-all">
  <tr>
    <th>客戶</th>
    <th>城市</th>
    <th>國家</th>
  </tr>
  <tr appml-repeat="records">
    <td>{{CustomerName}}</td>
    <td>{{City}}</td>
    <td>{{Country}}</td>
  </tr>
</table>
</div>
自己試試 »

建立帶有多個記錄的本地資料庫

要建立包含多個記錄的表,請使用類似這樣的模型:**proto_customers_all.js**。

將資料來源更改為 **local?model=proto_customers_all**

示例

<div class="w3-container" appml-data="local?model=proto_customers_all">
<h1>客戶</h1>
<table class="w3-table-all">
  <tr>
    <th>客戶</th>
    <th>城市</th>
    <th>國家</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>客戶</h1>
<div appml-include-html="inc_listcommands.htm"></div>

<table class="w3-table-all">
  <tr>
    <th>客戶</th>
    <th>城市</th>
    <th>國家</th>
  </tr>
  <tr appml-repeat="records">
    <td>{{CustomerName}}</td>
    <td>{{City}}</td>
    <td>{{Country}}</td>
  </tr>
</table>
</div>
自己試試 »

×

聯絡銷售

如果您想將 W3Schools 服務用於教育機構、團隊或企業,請傳送電子郵件給我們
sales@w3schools.com

報告錯誤

如果您想報告錯誤,或想提出建議,請傳送電子郵件給我們
help@w3schools.com

W3Schools 經過最佳化,旨在方便學習和培訓。示例可能經過簡化,以提高閱讀和學習體驗。教程、參考資料和示例會不斷審查,以避免錯誤,但我們無法保證所有內容的完全正確性。使用 W3Schools 即表示您已閱讀並接受我們的使用條款Cookie 和隱私政策

版權所有 1999-2024 Refsnes Data。保留所有權利。W3Schools 由 W3.CSS 提供支援