2016-07-07 28 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