我有以下模板:
{% block begin_content scoped %}
<div class="table-responsive">
<table class="table table-bordered table-hover">
{% endblock %}
{% block begin_loop_values %}
{% if actions %}
<th>Diagnosis</th>
<th>MRN</th>
<th>Max Dx Date</th>
{% endif %}
{% for item in value_columns %}
{% for dx in value_columns | groupby('dx_code') %}
{% for person in group.list | groupby('mrn') %}
<div class="table-responsive">
<td>{{ dx.grouper }}</td>
<td>{{ person.grouper }}</td>
</div>
{% endfor %}
{% endfor %}
{% endfor %}
{% endblock %}
{% block end_content scoped %}
</table>
</div>
{%endblock%}
我将数据分组如下:
{'dx_code': u'1234', 'mrn': u'12345678', 'dx_date': u'1/28/2015'}
{'dx_code': u'1234', 'mrn': u'12345678', 'dx_date': u'1/28/2014'}
{'dx_code': u'1234', 'mrn': u'12345678', 'dx_date': u'1/28/2013'}
{'dx_code': u'1234', 'mrn': u'12345678', 'dx_date': u'1/28/2012'}
{'dx_code': u'1234', 'mrn': u'12345678', 'dx_date': u'1/28/2011'}
效果很好,但现在我需要以某种方式获取MAX dx_date
并将其与我的模板中的分组数据一起打印出来。我假设我需要插入一个jQuery函数来执行此操作 - 类似于
<script language="javascript">
var latest = new Date(Math.max.apply(null, dx.dx_date));
</script>
,但我不确定如何将它的价值纳入我的模板?