【问题标题】:Spring fmt tags + handlebars.js template + ajaxSpring fmt标签+handlebars.js模板+ajax
【发布时间】:2014-08-18 12:35:47
【问题描述】:

我正在使用 springs fmt 标签来显示发表评论的日期。像这样:

<fmt:formatDate type="both" value="${comment.date}" />

这适用于所有已发布的 cmets。 (写在页面加载)

问题在于使用 ajax 动态添加新评论时。

然后我使用如下的车把模板。

<script id="new-comment-template" type="text/x-handlebars-template">
    <div class="discussion-comment" id="{{id}}">
        <h4 class="inline">
            <small>
                <a href="/users/{{userId}}" class="text-primary inline">{{name}}</a> at {{university}} {{date}}
            </small>
        </h4>
        <form id="command" class="pull-right inline" action="/courses/${course.id}/${course.name}/comment/{{id}}"
              method="post"><input type="hidden" name="_method" value="delete">
            <button type="submit" class="btn btn-danger btn-sm">
                <i class="fa fa-trash-o fa-lg"></i>
            </button>
        </form>
        <p>{{{message}}}</p>
    </div>
</script>

但是我来自服务器的{{date}} 变量的格式错误,如果我正在尝试

<fmt:formatDate type="both" value="{{date}}" />

我收到一个错误,因为在解析模板时该值不存在(我猜)。

我喜欢使用 springs fmt:formatDate 标签,因为它可以处理我的国际化。

有可能吗?

如果不是,我正在考虑一些替代方案:

  1. 跟踪客户端的时间。不断更新,写“5min ago”,“10min ago”等等。直到页面刷新。
  2. 尝试直接从服务器发送正确格式的时间。是否可以在服务器端运行 fmt:formatDate?

感谢您的建议。

【问题讨论】:

    标签: jquery ajax spring spring-mvc internationalization


    【解决方案1】:

    您可能会发现 Moment.JS 可以解决此问题。

    【讨论】:

      猜你喜欢
      • 2013-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-05
      • 1970-01-01
      • 2013-07-19
      • 2015-11-19
      相关资源
      最近更新 更多