object 对象

创建对象,只对 schema.type="object" 时有效。

代码演示

object 对象 - 图1

基础样例

最简单的用法。

  1. import { Component } from '@angular/core';
  2. import { SFSchema } from '@delon/form';
  3. import { NzMessageService } from 'ng-zorro-antd/message';
  4. @Component({
  5. selector: 'form-object-simple',
  6. template: `<sf [schema]="schema" (formSubmit)="submit($event)"></sf>`
  7. })
  8. export class FormObjectSimpleComponent {
  9. schema: SFSchema = {
  10. properties: {
  11. name: { type: 'string' },
  12. age: { type: 'number' }
  13. },
  14. required: [ 'name', 'age' ],
  15. ui: {
  16. // 指定 `label` 和 `control` 在一行中各占栅格数
  17. spanLabel: 4,
  18. spanControl: 5
  19. }
  20. };
  21. constructor(public msg: NzMessageService) { }
  22. submit(value: any) { this.msg.success(JSON.stringify(value)); }
  23. }

object 对象 - 图2

卡片容器

包含标题、内容、操作区域。

  1. import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
  2. import { SFObjectWidgetSchema, SFSchema } from '@delon/form';
  3. import { NzMessageService } from 'ng-zorro-antd/message';
  4. @Component({
  5. selector: 'form-object-card',
  6. template: `
  7. <sf *ngIf="schema" [schema]="schema" (formSubmit)="submit($event)"></sf>
  8. <ng-template #extra>
  9. <a (click)="msg.success('Success')">More</a>
  10. </ng-template>
  11. `,
  12. })
  13. export class FormObjectCardComponent implements OnInit {
  14. @ViewChild('extra', { static: true }) private extra: TemplateRef<void>;
  15. schema: SFSchema;
  16. constructor(public msg: NzMessageService) {}
  17. ngOnInit(): void {
  18. this.schema = {
  19. properties: {
  20. name: { type: 'string' },
  21. age: { type: 'number' },
  22. address1: {
  23. title: '地址1',
  24. type: 'object',
  25. properties: {
  26. country: { type: 'string' },
  27. city: { type: 'string' },
  28. zone: { type: 'string' },
  29. },
  30. ui: {
  31. type: 'card',
  32. cardExtra: this.extra,
  33. } as SFObjectWidgetSchema,
  34. },
  35. address2: {
  36. title: '地址2',
  37. type: 'object',
  38. properties: {
  39. country: { type: 'string' },
  40. city: { type: 'string' },
  41. zone: { type: 'string' },
  42. },
  43. ui: {
  44. type: 'card',
  45. showExpand: false,
  46. } as SFObjectWidgetSchema,
  47. },
  48. },
  49. required: ['name', 'age'],
  50. ui: {
  51. spanLabelFixed: 150,
  52. grid: { span: 12, gutter: 16 },
  53. } as SFObjectWidgetSchema,
  54. };
  55. }
  56. submit(value: any) {
  57. this.msg.success(JSON.stringify(value));
  58. }
  59. }

API

schema 属性

参数说明类型默认值
[properties]定义对象的属性{ [key: string]: SFSchema }-
[required]必填项属性string[]-
[maxProperties]最大属性个数,必须是非负整数number-
[minProperties]最小属性个数,必须是非负整数number-

ui 属性

参数说明类型默认值
[showExpand]是否显示扩展,点击隐藏内容,限 type === ‘card’booleantrue
[expand]展开状态,限 type === ‘card’booleantrue
[showTitle]是否显示标题booleanfalse
[type]渲染类型card, defaultdefault
[cardSize]等同 nzSize 属性small, defaultsmall
[cardBodyStyle]等同 nzBodyStyle 属性{ [key: string]: string }-
[cardBordered]等同 nzBordered 属性booleantrue
[cardExtra]等同 nzExtra 属性string, TemplateRef<void>-
[cardActions]等同 nzActions 属性Array<TemplateRef>-