Definitions

Definitions建立当前页面公共的配置项,在其他组件中可以通过$ref来引用当前配置项中的内容。

注意 definitions 只能在顶级节点中定义。

  1. {
  2. "definitions": {
  3. "aa": {
  4. "type": "input-text",
  5. "name": "jack",
  6. "value": "ref value",
  7. "labelRemark": "通过<code>\\$ref</code>引入的组件"
  8. }
  9. },
  10. "type": "page",
  11. "title": "引用",
  12. "body": [
  13. {
  14. "type": "form",
  15. "api": "api/xxx",
  16. "actions": [],
  17. "body": [
  18. {
  19. "$ref": "aa"
  20. }
  21. ]
  22. }
  23. ]
  24. }

树形结构

Definitions 最大的作用其实是能够实现对数据格式的递归引用,实现无限层级编辑:

  1. {
  2. "definitions": {
  3. "options": {
  4. "type": "combo",
  5. "multiple": true,
  6. "multiLine": true,
  7. "name": "options",
  8. "items": [
  9. {
  10. "type": "group",
  11. "body": [
  12. {
  13. "label": "名称",
  14. "name": "label",
  15. "type": "input-text",
  16. "required": true
  17. },
  18. {
  19. "label": "值",
  20. "name": "value",
  21. "type": "input-text",
  22. "required": true
  23. }
  24. ]
  25. },
  26. {
  27. "label": "包含子选项",
  28. "type": "switch",
  29. "name": "hasChildren",
  30. "mode": "inline",
  31. "className": "block"
  32. },
  33. {
  34. "$ref": "options",
  35. "label": "子选项",
  36. "name": "children",
  37. "visibleOn": "this.hasOwnProperty('hasChildren') && this.hasChildren",
  38. "addButtonText": "新增子选项"
  39. }
  40. ]
  41. }
  42. },
  43. "type": "page",
  44. "title": "引用",
  45. "body": [
  46. {
  47. "type": "form",
  48. "api": "api/xxx",
  49. "actions": [],
  50. "body": [
  51. {
  52. "$ref": "options",
  53. "label": "选项"
  54. },
  55. {
  56. "type": "static",
  57. "label": "当前值",
  58. "tpl": "<pre>${options|json}</pre>"
  59. }
  60. ]
  61. }
  62. ]
  63. }