All treeitem tag have children #1361

Closed
xieyu33333 opened this Issue Nov 17, 2015 · 12 comments

Projects

None yet

4 participants

@xieyu33333
Contributor
<tree>
    <div class="tree-item-wrap" each="{ data }" onselectstart="return false" ondragstart="return false">
        <div class="tree-item-row { root: level==1 }" onclick="{ select }" style="padding-left: { countPadding(level) }">
            <i class="tree-item-arrow" onclick="{ toggle }" if="{ children }"></i>
            <div>{ name }</div>
        </div>
        <ul class="tree-child-wrap" if={ isFolder() }>
            <tree data="{ children }"></tree>
        </ul>
    </div>

   <script> ......</script>
</tree>

My code like that, and I find I can't use children to judge the arrow's exist; All item tag have children property, even the item data not have children.

@lloydzhou

the child tree can judge count and trigger parent event to disable arrow.

@xieyu33333
Contributor

@lloydzhou but this.children should be undefined at the leaf node

@lloydzhou

i mean do not check child from parent, only check in children tree and update parent "tree-item-arrow" class.

@GianlucaGuarini
Member

@xieyu33333 can you please make a jsfiddle example?

@acousticseagull

For each of the children put an empty children array and then just check if the children array has a length. I've updated your fiddle https://jsfiddle.net/bj3fcb7v/2/

@acousticseagull

Actually you could do it like this also. https://jsfiddle.net/pk8wgxds/ which may be closer to what you were looking for.

@xieyu33333
Contributor

At the old version, http://jsfiddle.net/bj3fcb7v/1/ is OK, I think it is a bug

@acousticseagull

Yeah it seems like children should be undefined, but it's like it doesn't exist.

<tree each={ data }>
  { console.log(children) } // logs nothing
</tree>
<tree each={ item, i in data }>
  { console.log(children) } // logs undefined
</tree>
@GianlucaGuarini
Member

does this issue still exists in riot 2.3.12 I am unable to reproduce this issue

@GianlucaGuarini
Member

ah I probably know what's the issue.. the children property gets inherited from the parent if it's undefined that's why items without any children appears to have them as well this seems to be a bug

@GianlucaGuarini GianlucaGuarini added bug and removed question labels Dec 18, 2015
@GianlucaGuarini GianlucaGuarini self-assigned this Dec 18, 2015
@GianlucaGuarini GianlucaGuarini added this to the 3.0.0 milestone Mar 3, 2016
@GianlucaGuarini
Member

fixed in riot@3.0.0 http://jsfiddle.net/rx7aw7u8/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment