admin管理员组文章数量:1418076
I'm having an object property like so
pageSizeValues: {
type: Object
}
that is being instantiated like this
this.pageSizeValues = {10: 10, 25: 25, 50: 50};
Based on it I'd like to build a dropdown with 3 entries, that is by iterating over the pageSizeValues
<vaadin-select @change="${event => this.setLimit(event.target.value)}" value="${this.limit}" placeholder="Page Size" style="width: 80px">
<template>
<vaadin-list-box>
${Object.entries(this.pageSizeValues).forEach(([key, val]) =>
{ console.log(key + " " + val);
html`
<vaadin-item value=${key}>${val}</vaadin-item>
`
})}
</vaadin-list-box>
</template>
</vaadin-select>
While the console.log properly display the key-value pairs in the UI I'm not getting the items rendered at all.
I managed to render the items properly when the I was iterating over an array instead of an Object so I'm not sure where the issue might be.
I'm having an object property like so
pageSizeValues: {
type: Object
}
that is being instantiated like this
this.pageSizeValues = {10: 10, 25: 25, 50: 50};
Based on it I'd like to build a dropdown with 3 entries, that is by iterating over the pageSizeValues
<vaadin-select @change="${event => this.setLimit(event.target.value)}" value="${this.limit}" placeholder="Page Size" style="width: 80px">
<template>
<vaadin-list-box>
${Object.entries(this.pageSizeValues).forEach(([key, val]) =>
{ console.log(key + " " + val);
html`
<vaadin-item value=${key}>${val}</vaadin-item>
`
})}
</vaadin-list-box>
</template>
</vaadin-select>
While the console.log properly display the key-value pairs in the UI I'm not getting the items rendered at all.
I managed to render the items properly when the I was iterating over an array instead of an Object so I'm not sure where the issue might be.
Share Improve this question asked Nov 4, 2021 at 8:44 SergiuSergiu 2,6267 gold badges36 silver badges60 bronze badges1 Answer
Reset to default 9You need to return the html value or it is just created and discarded. The easiest way is to use map
instead of forEach
${Object.entries(this.pageSizeValues).map(([key, val]) =>
{ console.log(key + " " + val);
return html`
<vaadin-item value=${key}>${val}</vaadin-item>
`
})}
本文标签: javascriptlit element unable to render in for each loopStack Overflow
版权声明:本文标题:javascript - lit element unable to render in for each loop - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745254120a2649998.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论