【问题标题】:How to remove duplicate elements in a array using freemarker?如何使用freemarker删除数组中的重复元素?
【发布时间】:2019-01-15 06:18:24
【问题描述】:

我已经编写了用于在 C 中查找重复元素的代码,但现在我被困在 freemarker 中实现相同的代码有人可以帮忙吗?

int n, a[10], b[10], count = 0, c, d;

   printf("Enter number of elements in array\n");
   scanf("%d",&n);

   printf("Enter %d integers\n", n);
   for(c=0;c<n;c++)
      scanf("%d",&a[c]);

   for(c=0;c<n;c++)
   {
      for(d=0;d<count;d++)
      {
         if(a[c]==b[d])
            break;
      }
      if(d==count)
      {
         b[count] = a[c];
         count++;
      }
   }

   printf("Array obtained after removing duplicate elements\n");         
   for(c=0;c<count;c++)
      printf("%d\n",b[c]);

【问题讨论】:

  • 一个标签是C,代码好像是C。但是freemarker是java的东西,不是吗?你是在移植这个 C->java 吗?还是尝试使用 C 语言的 java 引擎?
  • 我需要在 netsuite 高级 pdf 模板中实现这个逻辑
  • 问题的根源在于 FreeMarker 并不是真正的编程语言……它是一种模板语言。想想 printf 但功能更强大。那么,如果数据模型内容本身无法更改,您至少可以在其中添加一些辅助 Java 类吗?模板可以自己引入和实例化这些类,它们只需要以某种方式存在于你的“类路径”中。
  • @ddekany 但我们仍然可以实现这个吗??

标签: html netsuite freemarker


【解决方案1】:

您可以使用 freemarker 序列。可能效率不高,但我用它来对发票等上接近最大尺寸的行进行分组。

<#assign seen_style = []>
<#list record.item?sort_by("custcol_stylesort")  as lineitem>
   <#assign groupId = lineitem.item>
   <#if seen_style?seq_contains(groupId)> <!-- no if body is intentional; skips seen style -->
   <#else>
     <#assign seen_style = seen_style + [groupId]>
     <p>Do something with ${groupId}</p>
   </#if>
</#list>

【讨论】:

    猜你喜欢
    • 2018-07-20
    • 1970-01-01
    • 2018-02-14
    • 2017-08-12
    • 2011-03-22
    • 2014-01-18
    • 2013-05-20
    相关资源
    最近更新 更多