Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested $repeats and $index values #70

Open
Joera opened this issue Jul 27, 2015 · 2 comments
Open

nested $repeats and $index values #70

Joera opened this issue Jul 27, 2015 · 2 comments

Comments

@Joera
Copy link

Joera commented Jul 27, 2015

Question: Who has an idea how i can get a parent $index value inside a child $repeat?

as in a html structure like

<node class="cluster"> //  first repeat - thinks rows
        <node class="particle"></node> // second repeat  -- think columns 
    </node>

and .js

behaviors: {

.cluster': {

        '$repeat': function(s_array) {
               var result = [];
               for (var i = 0; i < s_array.length; i++) { result.push({}); } 
               return result;
        },
        'position': function($index) 
                return [ s_array[$index][1], ];  
        },

},
'.particle': {

        '$repeat': function(s_array) {
            var result = [];
            for (var i = 0; i < s_array[PARENTINDEX][2]; i++) { result.push({}); } 
            return result;
        },
        'position': function() {
                return [$index, 0];      
        },

},

states: {

  s_array : [[1,11,8],[2,9,13],[2,9,23],[3,7,13],[4,6,19],[5,5,19],[6,4,8],[6,19,5],[7,4,7],[7,21,2],[8,4,6]]  

}

@ildar-samit
Copy link

You can create cluster as its own component, then do a repeat on the parent, passing the index down to cluster. This index in cluster will be the column number. Then cluster can have its own repeat inside of itself, which will be the row number.

@Joera
Copy link
Author

Joera commented Aug 8, 2015

Ah .. nesting components ..Thanks. I will give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants