我想将 dom-repeat 的第一个元素显示在表单上。其他应通过单击按钮添加。这种情况如何在 polymer 中成为可能。如图所示。
如上图所示,默认情况下应显示 room#1,并应在单击按钮时添加 room#2。
代码-
<form is="iron-form" id="form" method="post" action="/form/handler">
<template is='dom-repeat' items='{{ rooms }}'>
<div class="head">
<paper-item>
<div id="line"><span>Room# {{displayIndex(index)}}</span></div>
<template is='dom-if' if='{{displayIndex != 1}}'>
<paper-button toggles class=button on-click="deleteRoom"><img src="trash.png" height="20px" width="20px"></paper-button>
</template>
</paper-item>
</div>
<choice-form room="{{displayIndex(index)}}">{{ item.room }}</choice-form>
</template>
</form>
最佳答案
我将创建一个仅包含第一个房间 (room#1) 的新数组,然后单击按钮将 room#2 添加到该数组,然后在 dom-repeat 中使用此数组而不是 房间
。
关于javascript - 如何让第一个元素显示在 dom-repeat 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42198248/