【问题标题】:How can I pass this string through thymeleaf th:replace?如何通过 thymeleaf th:replace 传递这个字符串?
【发布时间】:2016-09-21 19:45:30
【问题描述】:

原来我的 index.html 是这样的:

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

哪个有效!

我将该部分分离到一个外部 edit.html 文件中,并将其与 thymeleafs th:replace 包含到我的 index.html 中:

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

片段/editor.html:

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

我收到此错误:

org.thymeleaf.exceptions.TemplateProcessingException:无法解析 作为分配序列:"${binding}" (fragments/editor:9)

data-bind 是来自 knockout.js 的绑定。

我认为错误与“'\'”的转义有关

【问题讨论】:

    标签: javascript java spring-mvc knockout.js thymeleaf


    【解决方案1】:

    我明白了:

    index.html:

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

    editor.html:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多