Skip to content

Commit 35e9279

Browse files
authored
📚 Updated README for event listeners
1 parent 57b92b9 commit 35e9279

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

README.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,56 @@ export default class App extends Vue {
126126

127127
To carter for advanced cases where `children` of the hierachical tree may be of different types. And you want to perform some further actions whenever something happens to them. You can subscribe for checked events of item types you may be interested in. And perform further actions.
128128

129+
### Use case
129130
E.g A school has departments, and you want to check some departments and delete them.
130131

131-
| School
132-
|------- Department A
133-
|------- Department B
134-
132+
### Solution
135133
You can attach callbacks that notify you when departments have been checked on the tree.
136134

137-
Example
135+
### How to Use
136+
137+
```html
138+
<template>
139+
<!-- Examples of how to subscribe for events -->
140+
<tree-view :treeViewItems="schools" @created="customiseSchools" />
141+
</template>
142+
```
143+
```ts
144+
<script lang='ts'>
145+
import { Vue, Component} from 'vue-property-decorator';
146+
147+
import { TreeViewCreatedEventPayload } from '@/businessLogic/contracts/types';
148+
149+
@Component
150+
export default class App extends Vue {
151+
customiseSchools(treeCreatedEvent: TreeViewCreatedEventPayload) {
152+
const customisations = treeCreatedEvent.itemCustomisations;
153+
const eventManager = treeCreatedEvent.eventManager;
154+
155+
eventManager.subscribeToItemChecked("department", (items) => console.log(items));
156+
customisations.makeItemsCheckable(["department"]);
157+
}
158+
schools: TreeViewItem[] = [
159+
{
160+
id: '1',
161+
type: 'school',
162+
name: 'Vue School',
163+
children: [
164+
{
165+
id: '2',
166+
type: 'department',
167+
name: 'Typescript Department',
168+
parentId: '1'
169+
},
170+
{
171+
id: '3',
172+
type: 'department',
173+
name: 'Open Source Department',
174+
parentId: '1'
175+
}
176+
]
177+
}
178+
]
179+
}
180+
```
181+

0 commit comments

Comments
 (0)