Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
tree-select 组件:实现了删除 tag 同时取消 tree 对应节点的选中状态
Browse files Browse the repository at this point in the history
  • Loading branch information
xxapp committed Jul 26, 2017
1 parent 2f338be commit de83e97
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion components/ms-tree-select/ms-tree-select-panel.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div style="overflow: auto">
<xmp is="ms-tree" :widget="{checkable: @multiple,tree: @treeData, onSelect:@handleSelect, onCheck:@handleCheck}"></xmp>
<xmp is="ms-tree" :widget="{checkable: @multiple,tree: @treeData, checkedKeys:@checkedKeys, onSelect:@handleSelect, onCheck:@handleCheck}"></xmp>
</div>
4 changes: 3 additions & 1 deletion components/ms-tree-select/ms-tree-select-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function (cmpVm) {
return avalon.vmodels[cmpVm.panelVmId];
}

return avalon.define({
const vm = avalon.define({
$id: cmpVm.panelVmId,
checkedKeys: [],
selection: [],
Expand Down Expand Up @@ -72,4 +72,6 @@ export default function (cmpVm) {
cmpVm.selection = selection;
}
});

return vm;
}
16 changes: 15 additions & 1 deletion components/ms-tree-select/ms-tree-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,18 @@ avalon.define({
### 组件参数

| 参数 | 说明 | 类型 | 默认值 |
|-----|-----|-----|-----|
|-----|-----|-----|-----|
| value | 默认值 | string\[\] | \[\] |
| multiple | 是否多选 | boolean | false |
| treeData | 树数据 | TreeNode\[\] | \[\] |
| showSearch | 是否显示搜索框 | boolean | false |

> 继承 [ms-control 组件](#!/form-control) 的所有参数
TreeNode

| 参数 | 说明 | 类型 | 默认值 |
|-----|-----|-----|-----|
| title | 标题 | string | - |
| key | 节点标识 | string | - |
| children | 子节点 | TreeNode\[\] | - |
2 changes: 1 addition & 1 deletion components/ms-tree-select/ms-tree-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ controlComponent.extend({
this.selection.removeAll(o => o.key === option.key);
const selection = this.selection.toJSON();
const value = selection.map(s => s.key);
avalon.vmodels[this.panelVmId].selection = selection;
avalon.vmodels[this.panelVmId].checkedKeys = value;
this.focusSearch();
this.handleChange({
target: { value: this.multiple ? value : value[0] || '' },
Expand Down
2 changes: 1 addition & 1 deletion components/ms-tree/ms-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ TreeNode
|-----|-----|-----|-----|
| title | 标题 | string | - |
| key | 节点标识 | string | - |
| children | 子节点 | TreeNodep\[\] | - |
| children | 子节点 | TreeNode\[\] | - |
11 changes: 8 additions & 3 deletions components/ms-tree/ms-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ avalon.component('ms-tree', {
});
const checkedKeys = checkedNodes.map(n => n.key);

this.checkedKeys = checkedKeys
//this.checkedKeys = checkedKeys
this.onCheck(checkedKeys, {
checked: node.checked,
checkedNodes: checkedNodes,
Expand Down Expand Up @@ -62,8 +62,13 @@ avalon.component('ms-tree', {
}
}, this.tree.toJSON());

treeObj.getNodesByFilter(n => this.checkedKeys.contains(n.key)).forEach(n => {
treeObj.checkNode(n, true, true);
this.$fire('checkedKeys', this.checkedKeys);

this.$watch('checkedKeys', v => {
treeObj.checkAllNodes(false);
treeObj.getNodesByFilter(n => v.contains(n.key)).forEach(n => {
treeObj.checkNode(n, true, true);
});
});
}
}
Expand Down

0 comments on commit de83e97

Please sign in to comment.