feat: tree add parent for event callback

#4849
pull/4861/head
tangjinzhou 2021-11-05 13:21:19 +08:00
parent bbf1cc8a6f
commit 8f77208806
4 changed files with 8 additions and 2 deletions

View File

@ -119,7 +119,10 @@ export default defineComponent({
});
const instance = getCurrentInstance();
const eventData = computed(() => {
return convertNodePropsToEventData(props);
const { eventKey } = props;
const { keyEntities } = context.value;
const { parent } = keyEntities[eventKey] || {};
return { ...convertNodePropsToEventData(props), parent };
});
const dragNodeEvent: DragNodeEvent = reactive({
eventData,

View File

@ -34,6 +34,7 @@ export interface EventDataNode extends DataNode {
pos?: string;
active?: boolean;
dataRef?: DataNode;
parent?: DataNode;
eventKey?: Key; // v2 key
}

View File

@ -45,6 +45,8 @@ export const treeNodeProps = {
/** New added in Tree for easy data access */
data: { type: Object as PropType<DataNode>, default: undefined as DataNode },
parent: { type: Object as PropType<DataNode>, default: undefined as DataNode },
isStart: { type: Array as PropType<boolean[]> },
isEnd: { type: Array as PropType<boolean[]> },
active: { type: Boolean, default: undefined },

View File

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