简体   繁体   English

我怎样才能通过百里香th:replace传递这串琴弦?

[英]How can I pass this string through thymeleaf th:replace?

Originally my index.html looked like this: 最初,我的index.html看起来像这样:

<div data-bind="attr: {id: 'newsEntry_'+ $parentContext.$index() +'_lead_' + $index() + '_toolbar'}">
                    ...
</div>

which works! 哪个有效!

I separated that part to an external edit.html file and includet it with thymeleafs th:replace to my index.html: 我将该部分分离到一个外部edit.html文件中,并将其与百里香th:replace一起包含到我的index.html中:

<div th:replace="fragments/editor :: editor(binding='data-bind=\'attr: {id: \'newsEntry_\'+ $parentContext.$index() +\'_lead_\' + $index() + \'_toolbar\'}\'')" >...</div>

fragments/editor.html: fragment / editor.html:

<div th:fragment="editor(binding)">
    <div th:attr="${binding}">...</div>
</div>

I get this error: 我收到此错误:

org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as assignation sequence: "${binding}" (fragments/editor:9) org.thymeleaf.exceptions.TemplateProcessingException:无法解析为分配序列:“ $ {binding}”(片段/编辑器:9)

data-bind is the binding from knockout.js. 数据绑定是来自基因敲除.js的绑定。

I think the error is something with the escpaing of " ' \\' 我认为错误在于“'\\”

I got it: 我知道了:

index.html: index.html:

<div th:replace="fragments/editor :: editor(binding='attr:{ id: \'newsEntry_\'+ $parentContext.$index() +\'_lead_\' + $index() + \'_toolbar\'}')" >...</div>

editor.html: editor.html:

<div th:fragment="editor(binding)">
    <div th:attr="data-bind=${binding}"></div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 thymeleaf th:if 中拨打 javascript function? - How can I call javascript function in thymeleaf th:if? 如何将查询字符串传递给window.location.replace()? - How can I pass a query string to window.location.replace()? 如何使用 Thymeleaf th:if 调用 javascript function 没有 ZC0BB2196426022E8AEDF9A5B? - How can I use Thymeleaf th:if to call javascript function without onclick? 如何将百里香String变量传递给javascript参数? - How to pass thymeleaf String variable to javascript parameters? 如何替换字符串? - How can I replace a string? 如何使用 thymeleaf onclick 在单个 Javascript 方法中传递多个 arguments - How to pass multiple arguments in a single Javascript method using thymeleaf onclick (th:onclick) 我如何使用javascript替换字符串右端的第x个字符? - how do i replace the x'th character from the right end of a string using javascript? 如何遍历字符串并替换除最后一个以外的所有句点? - How can I loop through string and replace all periods except the last one? 如何将百里香中的“数组”属性(从springboot控制器发送)传递给Javascript并进行迭代? - How can I pass “array” attribute (sent from springboot controller) from thymeleaf to Javascript and iterate? 如何在 thymeleaf/html 中以单一形式遍历常见字段集 - How can I loop through common fieldsets in a single form in thymeleaf/html
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM