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); }