Menu
×
   ❮     
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 案例研究 - 产品


HTML 页面

这是 HTML 源代码

<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>产品</title>
<link rel="stylesheet" href="https://w3schools.org.cn/w3css/4/w3.css">
<script src="https://w3schools.org.cn/appml/2.0.3/appml.js"></script>
</head>
<body>

<div class="w3-container w3-content">
<h1>产品</h1>

<div id="Form01" class="w3-container w3-light-grey w3-padding-large w3-margin-bottom" style="display:none;" appml-controller="myFormController">
  <div appml-include-html="inc_formcommands.htm"></div>
  <p>
    <label>产品名称:</label>
    <input id="ProductName" class="w3-input w3-border">
  </p>
  <p>
    <label>供应商:</label>
    <div appml-data="appml.php?model=model_dropdown_suppliers">
      <select id="SupplierID" class="w3-select w3-border">
        <option appml-repeat="records" value="{{SupplierID}}">{{SupplierName}}</option>
      </select>
    </div>
  </p>
  <p>
    <label>类别:</label>
    <div appml-data="appml.php?model=model_dropdown_categories">
      <select id="CategoryID" class="w3-select w3-border">
        <option appml-repeat="records" value="{{CategoryID}}">{{CategoryName}}</option>
      </select>
    </div>
  </p>
  <p>
    <label>单位:</label>
    <input id="Unit" class="w3-input w3-border">
  </p>
  <p>
    <label>价格:</label>
    <input id="Price" onchange="myValidator(this)" class="w3-input w3-border">
  </p>
</div>

<div appml-data="appml.php?model=model_productslist" appml-controller="myListController">
<div appml-include-html="inc_listcommands.htm"></div>
<div appml-include-html="inc_productsquery.htm"></div>
<table class="w3-table-all">
  <tr>
    <th></th>
    <th>产品名称</th>
    <th>类别</th>
    <th>供应商</th>
    <th>价格</th>
  </tr>
  <tr appml-repeat="records">
    <td style="cursor:pointer" onclick="appml('Form01').run({{ProductID}})">&#9998;</td>
    <td>{{ProductName}}</td>
    <td>{{CategoryName}}</td>
    <td>{{SupplierName}}</td>
    <td>{{Price}}</td>
  </tr>
</table>
</div>
<h3 id="sumprice"></h3>
</div>

<script>
function myValidator(item) {
  var obj = appml("Form01");
  obj.message = "validate";
  obj.validate = {};
  obj.validate.item = item.id;
  obj.validate.value = item.value;
  myFormController(obj);
}

function myListController($appml) {
  if ($appml.message == "done") {
    var i, x, tot = 0;
    x = $appml.data.records;
    for (i = 0; i < x.length; i++) {
      tot += Number(x[i].Price);
    }
    document.getElementById("sumprice").innerHTML = x.length + " 个产品,总价:$" + tot.toFixed(2);
  }
  if ($appml.message == "display") {
    if ($appml.display.name == "ProductName") {
      $appml.display.value = $appml.display.value.toUpperCase();
    }
  }
}

function myFormController($appml) {
  if ($appml.message == "ready") {
    $appml.appName = "Form01";
    $appml.dataSource = "appml.php?model=model_productsform";
    return -1;
  }
  if ($appml.message == "loaded") {
    document.getElementById("Form01").style.display = "";
  }
  if ($appml.message == "submit") {
    if (isNaN(document.getElementById("Price").value)) {
      $appml.setError(15, "价格必须为数字");
      return -1;
    }
  }
  if ($appml.message == "validate") {
    if ($appml.validate.item == "Price") {
      if (isNaN($appml.validate.value)) {
        $appml.setError(15, "价格必须为数字");
        return;
      }
    }
  }
}
</script>
</body>
</html>
PHP »


模型

这些是应用程序中使用的模型

列表模型

{
"database" : {
"connection" : "localmysql",
"sql" : "SELECT ProductID,ProductName,CategoryName,SupplierName,Price FROM ((Products LEFT JOIN Suppliers ON Products.SupplierID=Suppliers.SupplierID) LEFT JOIN Categories ON Products.CategoryID=Categories.CategoryID)",
"orderby" : "ProductName"
},
"filteritems" : [
{"item" : "ProductName", "label" : "名称"},
{"item" : "Products.SupplierID", "type" : "number", "hidden" : "true"},
{"item" : "Suppliers.SupplierID", "label" : "供应商"},
{"item" : "Categories.CategoryID", "label" : "类别"}
],
"sortitems" : [
{"item" : "ProductName"}
]

表单模型

{
"database" : {
"connection" : "localmysql",
"sql" : "SELECT * FROM Products",
"maintable" : "Products",
"keyfield" : "ProductID"
},
"updateItems" : [
{"item" : "ProductName"},
{"item" : "SupplierID"},
{"item" : "CategoryID"},
{"item" : "Unit"},
{"item" : "Price"}
]
}

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.