AppML - 第一個應用程式
讓我們從一個簡單的應用程式開始。
步驟 1:建立資料
第一步是建立一個數據檔案,該檔案將提供要在應用程式 UI 中顯示的記錄。建立 students-data.js
students_records.js
{
"students":[
{"studentName":"Ramesh","class":"12","section":"White"},
{"studentName":"Suresh","class":"12","section":"Red"},
{"studentName":"Mohan","class":"12","section":"Red"},
{"studentName":"Robert","class":"12","section":"Red"},
{"studentName":"Julie","class":"12","section":"White"},
{"studentName":"Ali","class":"12","section":"White"},
{"studentName":"Harjeet","class":"12","section":"White"}
]}
步驟 2:建立應用程式 HTML
student_application.html
<!DOCTYPE html>
<html lang="en-US">
<title>Students</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
text-align: left;
padding: 8px;
}
tr:nth-child(even) {background-color: #f2f2f2;}
</style>
<script src="https://w3schools.tw/appml/2.0.3/appml.js"></script>
<body>
<table appml-data="students_records.js" appml-controller="myController">
<tr>
<th>Student</th>
<th>Class</th>
<th>Section</th>
</tr>
<tr appml-repeat="students">
<td>{{studentName}}</td>
<td>{{class}}</td>
<td>{{section}}</td>
</tr>
</table>
<script>
function myController($appml) {
if ($appml.message == "display") {
if ($appml.display.name == "studentName") {
$appml.display.value = $appml.display.value.toUpperCase();
}
}
}
</script>
</body>
</html>
輸出
在 Web 伺服器上部署應用程式並訪問 html 頁面。驗證輸出。
廣告