Skip to content

Commit

Permalink
1. 项目移除时同时移除子项目
Browse files Browse the repository at this point in the history
  • Loading branch information
bplok20010 committed Jun 13, 2019
1 parent f2f6788 commit e60b884
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
15 changes: 13 additions & 2 deletions lib/DesignModel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "form-design-core",
"version": "0.3.0",
"version": "0.4.0",
"description": "表单设计器",
"main": "lib/index.js",
"scripts": {
Expand Down
12 changes: 11 additions & 1 deletion src/DesignModel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit e60b884

Please sign in to comment.