[英]How to add html line break after each item in Javascript loop?
I would like to display a list in my web component, with a line break, the problem is that my function that loops on the list is in Javascript, and I call it in my html. 我想用换行符在Web组件中显示一个列表,问题是我在列表上循环的函数是Javascript,我用html调用了它。 How can I do it?
我该怎么做?
I tried : 我试过了 :
result.join("\\n");
//this work on console result.join( html ``<br/>``);
//(Windsor[object HTMLTemplateElement]groot ) result.push(value,"\\n");
//(Windsor, ,groot) Javascript Java脚本
_getValues(field)
{
switch (field.type) {
...
default:
if (this.values.length) {
for (const [index, value] of this.values.entries()) {
result.push(value);
}
return result;
} else
return (this.values);
}
HTMLTemplate Polymer 3.0 HTMLTemplate聚合物3.0
static get template() {
return html `
...
<template is="dom-repeat" items="{{fields}}">
<span><b> item :</b> <br> [[_getValues(item)]] </span>
</template> `
I expect the output in the IHM like this : 我希望这样的IHM输出:
Windsor
groot
But i have this : 但是我有这个:
Windsor,groot
or Windsor,,groot or Windsor[object HTMLTemplateElement]groot 或Windsor 、, groot或Windsor [object HTMLTemplateElement] groot
I think that this would work if your fields object looked more like this 我认为,如果您的字段对象看起来更像这样,这将起作用
fields : [
{name: 'Windsor', value: 'groot'}
]
<template is="dom-repeat" items="{{fields}}">
<div><b> name :</div> <div> value </div>
</template>
If calling your function in the template is working then this should work as well 如果在模板中调用您的函数正常工作,那么这也应该工作
<div><b> item :</b></div> <div> [[_getValues(item)]] </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.