table-test.html 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>表格渲染测试</title>
  6. <script src="https://unpkg.com/juris"></script>
  7. <style>
  8. body { font-family: Arial, sans-serif; padding: 20px; }
  9. table { border-collapse: collapse; width: 100%; }
  10. th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
  11. th { background-color: #f2f2f2; }
  12. </style>
  13. </head>
  14. <body>
  15. <h1>Juris 表格渲染测试</h1>
  16. <div id="app"></div>
  17. <script>
  18. // 测试数据
  19. const testData = [
  20. { id: 1, name: "测试用户1", role: "管理员" },
  21. { id: 2, name: "测试用户2", role: "用户" }
  22. ];
  23. // 创建表格渲染函数
  24. function renderTestTable(data) {
  25. return {
  26. tag: "table",
  27. children: [
  28. // 表头
  29. {
  30. tag: "thead",
  31. children: [
  32. {
  33. tag: "tr",
  34. children: [
  35. { tag: "th", text: "ID" },
  36. { tag: "th", text: "姓名" },
  37. { tag: "th", text: "角色" }
  38. ]
  39. }
  40. ]
  41. },
  42. // 表体 - 使用数组格式
  43. {
  44. tag: "tbody",
  45. children: data.map(item => ({
  46. tr: {
  47. children: [
  48. { tag: "td", text: item.id.toString() },
  49. { tag: "td", text: item.name },
  50. { tag: "td", text: item.role }
  51. ]
  52. }
  53. }))
  54. }
  55. ]
  56. };
  57. }
  58. // 创建Juris应用
  59. const app = new Juris({
  60. states: {
  61. tableData: testData
  62. },
  63. layout: {
  64. tag: "div",
  65. children: [
  66. { tag: "h2", text: "简单表格测试" },
  67. () => renderTestTable(app.getState("tableData"))
  68. ]
  69. }
  70. });
  71. // 渲染应用
  72. app.render('#app');
  73. console.log("应用已渲染");
  74. </script>
  75. </body>
  76. </html>