JJJ
JJJ

Reputation: 2909

How do you map an array using Polymer's dom-repeat

I'm currently trying to map an array of strings I have to its corresponding object... but cannot find a way to do the map it.

I want to do something like this below (I know syntax is not correct, but trying to get my point across)

// user.connections ["1","2","3"]
<template is="dom-repeat" items="{{user.connections}}" as="connection"
            map="isAppConnection" observe="app.id">
 {{connection}} <!-- The actual object -->
</template>

Upvotes: 2

Views: 272

Answers (1)

miyamoto
miyamoto

Reputation: 1540

Use computed bindings

<dom-module is="some-element">
<template is="dom-repeat" items="{{isAppConnection(user.connections)}}" as="connection">
    {{connection}}
</template>
</dom-module>

<script>
Polymer({
    is: "some-element",
    properties: {user: Object},
    isAppConnection: function(connections){
       connections.map(e=>SomeObj[e])
    },
})
</script>

Upvotes: 2

Related Questions