نموذج AppML
في هذا الفصل ، سنبني نموذجًا أوليًا لتطبيق ويب.
قم بإنشاء نموذج HTML أولي
أولاً ، قم بإنشاء نموذج أولي لائق بتنسيق HTML ، باستخدام CSS المفضل لديك.
استخدمنا 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 = "سجلات"
لتبسيط الأمر ، ابدأ بالبيانات المحلية مثل قبل الاتصال بقاعدة البيانات.
قم بإنشاء نموذج AppML
لتتمكن من استخدام قاعدة بيانات ، ستحتاج إلى نموذج قاعدة بيانات AppML:
proto_customers.js
{
"rowsperpage" : 10,
"database" : {
"connection"
: "localmysql",
"sql" : "Select * from Customers",
"orderby"
: "CustomerName",
}
إذا لم يكن لديك قاعدة بيانات محلية ، يمكنك استخدام نموذج AppML لإنشاء قاعدة بيانات Web SQL.
لإنشاء جدول بسجل واحد ، استخدم نموذجًا مثل هذا: .
لا يعمل إنشاء قاعدة بيانات محلية في 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'>❮❮</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>
احفظ القالب في ملف باسم مناسب مثل "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>