繁体   English   中英

如何在大豆模板中得到子串?

[英]how to get substring in soy template?

我有大豆模板,如果长度超过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)

我不认为Closure模板允许您在对象上调用JavaScript函数。 带来的不便之处是,在将{$attributes.subAccountNumber}传递给模板(使用Java或JS)之前,您需要先对其进行评估。 我相信这是由于它仍然是模板系统而不是JS库。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM