gpt4 book ai didi

javascript - 如何获取 soy 模板中的子字符串?

转载 作者:行者123 更新时间:2023-12-03 08:17:40 25 4
gpt4 key购买 nike

我有大 bean 模板,如果长度超过 30 个字符,我只需要 28 个字符?如何得到它?

   {if $attributes.subAccountNumber.length < 30}
<td>{$attributes.subAccountNumber}</td>
{else}
</td>{$attributes.subAccountNumber.substring(0,28)}</td>
{/if}

但是在编译时它会抛出异常,

Exception in thread "main" com.google.template.soy.base.SoySyntaxException: In file war/js/Application/Reports/ViewTemplates/ReportsViewTemplate.soy:518, template acti.workflow.reports.transcriptCard: Not all code is in Soy V2 syntax (found tag {$attributes.subAccountNumber.substring(0,28)} not in Soy V2 syntax).
at com.google.template.soy.base.SoySyntaxException.createWithoutMetaInfo(SoySyntaxException.java:52)
at com.google.template.soy.soytree.SoySyntaxExceptionUtils.createWithNode(SoySyntaxExceptionUtils.java:48)
at com.google.template.soy.sharedpasses.AssertSyntaxVersionV2Visitor.visitSoyNode(AssertSyntaxVersionV2Visitor.java:105)
at com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitPrintNode(AbstractSoyNodeVisitor.java:221)
at com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:85)
at com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:55)
at com.google.template.soy.basetree.AbstractNodeVisitor.visitChildren(AbstractNodeVisitor.java:59)
at com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitChildren(AbstractSoyNodeVisitor.java:126)
at com.google.template.soy.sharedpasses.AssertSyntaxVersionV2Visitor.visitSoyNode(AssertSyntaxVersionV2Visitor.java:112)
at com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitIfElseNode(AbstractSoyNodeVisitor.java:253)
at com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:95)
at com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:55)

最佳答案

我不相信闭包模板允许您在对象上调用 JavaScript 函数。尽管很不方便,但在将 {$attributes.subAccountNumber} 传递给模板(在 Java 或 JS 中)之前,您需要对其进行评估。我相信这是因为它仍然是一个模板系统而不是一个 JS 库。

关于javascript - 如何获取 soy 模板中的子字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33868551/

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