gpt4 book ai didi

html - 在 Polymer 中使用重复模板时禁用数据绑定(bind)中的转义 HTML

转载 作者:太空宇宙 更新时间:2023-11-04 16:20:31 25 4
gpt4 key购买 nike

大家好,

        <template repeat="{{amendment in amendments}}">
<div layout horizontal>
<div>{{amendment['proposed_text']}}</div>
<div>{{amendment['amendment_text'])}</div>
</div>
</template>

proposed_textamendment_text包含 HTML 内容,例如 <br> .由于 Polymer 在使用数据绑定(bind)时会转义所有 HTML 内容,因此这些 <br>标签未显示。我在谷歌上搜索了一会儿并想出了 injectBoundHTML(expression, element)然而,这对我也不起作用,因为我没有单个元素,而是由 repeat 创建的 N 个元素。模板。

您可能猜到我的问题是,我怎样才能制作这些 <br>或在使用 repeat 的情况下通常可见的 HTML模板自 injectBoundHTML似乎在这里不起作用?

我目前使用的解决方案适用于我的情况,但如果 HTML 内容包含的不仅仅是 <br> 则将无效。 .

我目前的解决方案:

        <template repeat="{{amendment in amendments}}">
<div layout horizontal>
<div>
<template repeat="{{text in splitAtBrs(amendment['proposed_text'])}}">
{{text}}<br>
</template>
</div>
<div>
<template repeat="{{text in splitAtBrs(amendment['amendment_text'])}}">
{{text}}<br>
</template>
</div>
</div>
</template>

使用方法splitAtBrs :

 List<String> splitAtBrs(String s) {
return s.split("\n");
}

最佳答案

查看我上面的问题并查看 Answer #1Answer #2特别是Answer #3 .在答案 #3 中,他们使用:

. Dart :

String text = 'test<br/>foobar<br/><b>test</b>';
[...]
// somewhere in your code (e.g. in attached)
this.injectBoundHtml('xyz: ${text}', element: $['raw']);

.html:

<div id="raw"></div>

也许您也可以将其用于模板重复,例如如果您创建自己的函数,它将为您调用 injectBoundHTML

像这样的东西会起作用:

int i = 0;
texts.forEach((String text) {
this.injectBoundHtml('${text}', element: $['raw-${i}']);
i++;
});

在 .html 中:

<template repeat="{{text in texts | enumerate}}">
<div id="raw-{{text.index}}">{{text.index}}</div>
</template>

关于html - 在 Polymer 中使用重复模板时禁用数据绑定(bind)中的转义 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29730113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com