From e60b8844bb5d29bdc088ec4fa3c3b33a5022e788 Mon Sep 17 00:00:00 2001 From: bplok20010 <505931977@qq.com> Date: Thu, 13 Jun 2019 16:56:51 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E9=A1=B9=E7=9B=AE=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=97=B6=E5=90=8C=E6=97=B6=E7=A7=BB=E9=99=A4=E5=AD=90=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/DesignModel/index.js | 15 +++++++++++++-- package.json | 2 +- src/DesignModel/index.js | 12 +++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/DesignModel/index.js b/lib/DesignModel/index.js index c39a158..7bc7229 100644 --- a/lib/DesignModel/index.js +++ b/lib/DesignModel/index.js @@ -165,9 +165,20 @@ function (_React$Component) { }, { key: "removeItem", value: function removeItem(fieldId) { - var items = this.getAllItems(); + var _this2 = this; + + var items = this.getAllItems(); //移除指定项目及子项目 + var ret = items.filter(function (item) { - return item.fieldId !== fieldId; + var shouldRemove = item.fieldId === fieldId; + + if (!shouldRemove) { + var pids = _this2.getPids(item.fieldId); + + shouldRemove = pids.indexOf(fieldId) > -1; + } + + return !shouldRemove; }); this.onChange(ret); } diff --git a/package.json b/package.json index 4156e5e..b051f7e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "form-design-core", - "version": "0.3.0", + "version": "0.4.0", "description": "表单设计器", "main": "lib/index.js", "scripts": { diff --git a/src/DesignModel/index.js b/src/DesignModel/index.js index d51b250..51d5a6f 100644 --- a/src/DesignModel/index.js +++ b/src/DesignModel/index.js @@ -125,7 +125,17 @@ export default class DesignModel extends React.Component { removeItem(fieldId) { const items = this.getAllItems(); - const ret = items.filter(item => item.fieldId !== fieldId); + //移除指定项目及子项目 + const ret = items.filter(item => { + let shouldRemove = item.fieldId === fieldId; + + if (!shouldRemove) { + const pids = this.getPids(item.fieldId); + shouldRemove = pids.indexOf(fieldId) > -1; + } + + return !shouldRemove; + }); this.onChange(ret); }