Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template repeat inside template repeat - get all item names

I'm trying to realise a website using polymer 1.0. I have a custom element my-greeting with some template repeats inside.

What I would like to do, and I don't find how to do this, is to get a string called TARGET which looks like :

/constantPath/folder1/aaa.jpg
/constantPath/folder1/bbb.jpg
/constantPath/folder2/aaa.jpg
/constantPath/folder2/bbb.jpg

So the general string is : /constantPath/{{repeat1.id}}/{{repeat2.id}}.jpg

How can I do that ??

Here is my code :

<dom-module id="my-greeting">
  <template>
    <template is="dom-repeat" items="{{repeat1}}">
      <template is="dom-repeat" items="{{repeat2}}">
        Target : <iron-image src="TARGET"></iron-image>
      </template>
    </template>
  </template>

  <script>
    Polymer({
      is: 'my-greeting',
      ready: function() {
        this.repeat1 = [
            {id: 'folder1'},
            {id: 'folder2'}
        ];
        this.repeat2 = [
            {id: 'aaa'},
            {id: 'bbb'}
        ];
      }
    }
    );
  </script>

Thanks.

like image 992
user3553840 Avatar asked Dec 02 '25 16:12

user3553840


1 Answers

Here you go:

<dom-module id="my-greeting">
  <template>
    <template is="dom-repeat" items="{{repeat1}}" as="folderOne">
      <template is="dom-repeat" items="{{repeat2}}" as="folderTwo">
        Target : <span>{{getTarget(folderOne, folderTwo)}}</span></br>
      </template>
    </template>
  </template>

  <script>
    Polymer({
      is: 'my-greeting',
      ready: function() {
        this.repeat1 = [
            {id: 'folder1'},
            {id: 'folder2'}
        ];
        this.repeat2 = [
            {id: 'aaa'},
            {id: 'bbb'}
        ];
      },
      getTarget: function(folderOne, folderTwo){
        return "/constantPath/"+folderOne.id+"/"+folderTwo.id;
      },
    }
    );
  </script>
</dom-module>
like image 175
Flavio Ochoa Avatar answered Dec 04 '25 12:12

Flavio Ochoa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!