Geek Answers Handbook

    Vue.js nested v-repeat: how to access parent index $ index inside child element?

    I can not do it:

    <ul>
        <li v-repeat="candy: candies">
            <ul>
                <li v-repeat="flavour: candy.flavours">
                    {{ candy.$index }}
                </li>
            </ul>
        </li> 
    </ul>
    

    Any work around?

    +4
    vue.js
    aBhijit Jun 15 '15 at 19:14
    source share
    1 answer

    UPDATE 2: v-forNow supports specifying an alias for $index: http://vuejs.org/api/#v-for This should allow you to avoid naming collisions on $index.

    UPDATE: VueJS 1.0 is deprecated v-repeatin favor v-for. However, this is the same solution.


    Try to use $parent.$indexto access $indexin the parent area.

    +13
    David K. Hess Jun 20 '15 at 15:05
    source share

    More articles:

    • Как ΡΠΊΡ€Ρ‹Ρ‚ΡŒ Firefox Icon Icon Overlay Π² Windows - firefox
    • Packing an entire Python application as a PEX file - python
    • How to write a 3-byte Unicode character as a string literal - dart
    • Ionic Kli coming out after serving - javascript
    • Fire Trigger from DocumentDB Stored Procedure - triggers
    • In Visual Studio Extension, how to detect when the debugger continues - visual-studio
    • How to remove columns from data.table based on values ​​in column - r
    • Why doesn't my python program converge to pi? - python
    • Trying to write less_then character twice ("<<") using XSLT. This does not work if I try to write it twice - xml
    • gnuplot is slow when displaying big data as an animation - performance

    All Articles

    Geek Answers | 2019