holiber / sl-vue-tree

Customizable draggable tree component for Vue.js
MIT License
344 stars 79 forks source link

Cannot individually change the node icon #54

Closed ErikVerheul closed 5 years ago

ErikVerheul commented 5 years ago

So far your component worked great for me. However changing the icon of individual nodes seems impossible. If you change one you change them all. In the code snippet below I added two more icons depending on some conditions. When I click on the node with the bug icon all leaf items get the bug icon. Would be great if the next release supports changing individual nodes, either in the slot or via a method in JavaScript.

<template slot="title" slot-scope="{ node }">
<span class="item-icon">
    <i v-if="node.isLeaf && getCurrentItemSubType == 0">
        <font-awesome-icon icon="file" />
    </i>
    <i v-if="node.isLeaf && getCurrentItemSubType == 1">
        <font-awesome-icon icon="hourglass-start" />
    </i>
    <i v-if="node.isLeaf && getCurrentItemSubType == 2">
        <font-awesome-icon icon="bug" />
    </i>
    <i v-if="!node.isLeaf">
        <font-awesome-icon icon="folder" />
    </i>
</span>
{{ node.title }}
</template>

Thank you for your good work, Erik

ErikVerheul commented 5 years ago

Problem solved after making the conditions only dependent of the node data. Like this:

<template slot="title" slot-scope="{ node }">
<span class="item-icon">
    <i v-if="node.isLeaf && node.data.subtype == 0">
        <font-awesome-icon icon="file" />
    </i>
    <i v-if="node.isLeaf && node.data.subtype == 1">
        <font-awesome-icon icon="hourglass-start" />
    </i>
    <i class="colorRed" v-if="node.isLeaf && node.data.subtype == 2">
        <font-awesome-icon icon="bug" />
    </i>
    <i v-if="!node.isLeaf">
        <font-awesome-icon icon="folder" />
    </i>
</span>
{{ node.title }}
</template>