Skip to content

Commit 8f77208

Browse files
committed
feat: tree add parent for event callback
#4849
1 parent bbf1cc8 commit 8f77208

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

components/vc-tree/TreeNode.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ export default defineComponent({
119119
});
120120
const instance = getCurrentInstance();
121121
const eventData = computed(() => {
122-
return convertNodePropsToEventData(props);
122+
const { eventKey } = props;
123+
const { keyEntities } = context.value;
124+
const { parent } = keyEntities[eventKey] || {};
125+
return { ...convertNodePropsToEventData(props), parent };
123126
});
124127
const dragNodeEvent: DragNodeEvent = reactive({
125128
eventData,

components/vc-tree/interface.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface EventDataNode extends DataNode {
3434
pos?: string;
3535
active?: boolean;
3636
dataRef?: DataNode;
37+
parent?: DataNode;
3738
eventKey?: Key; // 兼容 v2, 推荐直接用 key
3839
}
3940

components/vc-tree/props.ts

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export const treeNodeProps = {
4545

4646
/** New added in Tree for easy data access */
4747
data: { type: Object as PropType<DataNode>, default: undefined as DataNode },
48+
parent: { type: Object as PropType<DataNode>, default: undefined as DataNode },
49+
4850
isStart: { type: Array as PropType<boolean[]> },
4951
isEnd: { type: Array as PropType<boolean[]> },
5052
active: { type: Boolean, default: undefined },

components/vc-tree/utils/treeUtil.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ export function getTreeNodeProps(
375375
checked: checkedKeys.indexOf(key) !== -1,
376376
halfChecked: halfCheckedKeys.indexOf(key) !== -1,
377377
pos: String(entity ? entity.pos : ''),
378-
378+
parent: entity.parent,
379379
// [Legacy] Drag props
380380
// Since the interaction of drag is changed, the semantic of the props are
381381
// not accuracy, I think it should be finally removed

0 commit comments

Comments
 (0)