From e45404d3b3af1c96f65f3965ee3a6abe8c0548be Mon Sep 17 00:00:00 2001 From: vellengs Date: Sat, 17 Mar 2018 14:01:35 +0800 Subject: [PATCH] Update form.component.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed schema support issue, schema.properties can be empty. for example: ``` "dateArrayRange": { "type": "array", "items": { "type": "string" }, "title": "日期范围", "default": [ "2018-01-02", "2018-02-03" ], "widget": { "id": "date-range", "format": "YYYY-MM-DD" } } ``` the schema is only part of ``` { "type": "string" } ``` --- lib/src/form.component.ts | 40 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/src/form.component.ts b/lib/src/form.component.ts index 17f09c5..d9c7a8b 100644 --- a/lib/src/form.component.ts +++ b/lib/src/form.component.ts @@ -70,29 +70,31 @@ export class FormComponent implements OnChanges { private coverProperty(schema: SFSchema) { const isHorizontal = this.layout === 'horizontal'; - Object.keys(schema.properties).forEach(key => { - const p = schema.properties[key]; - if (isHorizontal) { - if (schema.span_label_fixed) { - if (!p.span_label_fixed) p.span_label_fixed = schema.span_label_fixed; + if (schema.properties) { + Object.keys(schema.properties).forEach(key => { + const p = schema.properties[key]; + if (isHorizontal) { + if (schema.span_label_fixed) { + if (!p.span_label_fixed) p.span_label_fixed = schema.span_label_fixed; + } else { + if (!p.span_label) p.span_label = typeof schema.span_label === 'undefined' ? 5 : schema.span_label; + if (!p.span_control) p.span_control = typeof schema.span_control === 'undefined' ? 19 : schema.span_control; + if (!p.offset_control) p.offset_control = typeof schema.offset_control === 'undefined' ? null : schema.offset_control; + } } else { - if (!p.span_label) p.span_label = typeof schema.span_label === 'undefined' ? 5 : schema.span_label; - if (!p.span_control) p.span_control = typeof schema.span_control === 'undefined' ? 19 : schema.span_control; - if (!p.offset_control) p.offset_control = typeof schema.offset_control === 'undefined' ? null : schema.offset_control; + p.span_label = null; + p.span_control = null; + p.offset_control = null; } - } else { - p.span_label = null; - p.span_control = null; - p.offset_control = null; - } - if (p.items && p.type === 'array') { - this.coverProperty(p.items); - } + if (p.items && p.type === 'array') { + this.coverProperty(p.items); + } - if (p.properties && Object.keys(p.properties).length) - this.coverProperty(p); - }); + if (p.properties && Object.keys(p.properties).length) + this.coverProperty(p); + }); + } } private coverButtonProperty(schema: SFSchema) {