2016-07-07 54 views
1

我目前正在尝试映射一个字符串数组我有它的相应对象...但是找不到一个方法来做它的映射。你如何映射一个数组使用Polymer的dom-repeat

我想要做这样的事情如下(我知道的语法不正确,而是试图了解我的点)

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

回答

2

使用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> 
+0

将这个更新为user.connections更改? – Jaime

+0

是的,只要'user'是一个依赖属性并且'user.connections'不是未定义的。 – miyamoto