如何使用 AppML

引入脚本、声明应用、指定模型、跑起来的最小步骤。

Beginner
Key Points四步:引脚本、写页面里的 appml-app 标签、写 model.xml、起一个本地服务器。

第一步:引入脚本

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

The script must load before <appml-app>; putting it in <head> is simplest. It also works before </body>, since AppML scans the DOM once ready.

第二步:声明应用

HTML
<appml-app src="model.xml"></appml-app>
AttributeMeaning
srcXML 模型文件路径
app用于多应用共存
controller自定义 JS 控制器文件
data直接传数据,绕过模型

第三步:写模型

XML
<appml>
  <datasource>
    <database name="demo"></database>
    <query>SELECT id, name, city FROM customers</query>
  </datasource>
  <items>
    <item name="id"   label="编号" type="number" primarykey="true"/>
    <item name="name" label="姓名" required="true"/>
    <item name="city" label="城市"/>
  </items>
</appml>

第四步:起服务器

Bash
# 不能直接双击打开 index.html(file:// 下无法读取 model.xml)
python -m http.server 8000
Output
Serving HTTP on 0.0.0.0 port 8000 ...

Under file:// the browser blocks fetching local files, so AppML cannot read the model and fails. Serve it over HTTP — the usual reason a page stays blank after following a tutorial.

页面里能放什么

HTML
<h1>我的客户管理</h1>

<!-- 一个应用可以有多块,用 appml-view 指定视图 -->
<appml-app src="model.xml">
  <appml-view view="list"></appml-view>
  <appml-view view="form"></appml-view>
</appml-app>
AppML views (list / form / search) depend on both the model and the framework version, and attribute names differ between versions. Check the CDN version before copying another version's docs.

常见问题

SymptomCause
Blank page脚本没加载 / 用 file:// 打开
Model not foundsrc 路径错,或模型不在同目录
No dataquery 写错,或数据库配置无效
CORS error模型与页面不同源

Friends & Partners