0

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

1 回答 1

1

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

于 2015-11-28T08:46:19.020 回答