我可以动态追加表格行,但在嵌入值时会遇到问题。
我正在使用jinja2。
示例:
我通过文本框输入的内容如下:
日期自:20130201 * ID为“txtStartDate”
收件人:20130205 * id为“txtEndDate”
号码:10 * id是“txtAllotNumber”
输出应该是这样的:
□20130201 10空白
□20130202 10空白
□20130203 10空白
□20130204 10空白
□20130205 10空白
□是一个复选框
也应编辑空白部分。
这是不正确的输出:
20130210 20130205 10空白
这是我附加表格的方式:
var chkflg = "";
var newtrtag = '<tr class="centertext getData">';
newtrtag += '<td class="checkGet" style="padding-left: 20px;"><input class="chkGetData" type="checkbox" name="del_param" value="{{stay_ymd}},{{allot_number}},{{delete_flag}},{{re_release_ymd}}"></td>';
newtrtag += '<input type="hidden" id="quantity{{stock_count}}" name="quantity{{stock_count}}" value="{{allot_number}}">';
newtrtag += '<input type="hidden" name="save[{{stock_count}}]" value="{{stay_ymd}},{{allot_number}},{{delete_flag}},{{re_release_ymd}}">';
newtrtag += '{% set delete_flag_val = '0'%}';
newtrtag += '{% if delete_flag %}';
newtrtag += '{% set delete_flag_val = '1' %}';
newtrtag += '{% else%}';
newtrtag += '{% endif %}';
newtrtag += '<input type="hidden" id="delflag{{stock_count}}" name="delflag{{stock_count}}" value="{{delete_flag_val}}">';
newtrtag += '<input type="hidden" id="rerel{{stock_count}}" name="rerel{{stock_count}}" value="{{re_release_ymd}}">';
newtrtag += '<td style="width:70%;">'+ $("#txtStartDate").val() +' </td>';
newtrtag += '<td style="width:70%;">'+ $("#txtEndDate").val() +' </td>';
newtrtag += '<td style="width:70%;">'+ $("#txtAllotNumber").val() +' </td>';
newtrtag += '{% set delete_flag_chk = "" %}';
newtrtag += '{% if delete_flag == True %}';
newtrtag += '{% set delete_flag_chk = "Released" %}';
newtrtag += '{% else%}';
newtrtag += '{% set delete_flag_chk = "Unreleased" %}';
newtrtag += '{% endif %}';
newtrtag += '<td class="colStatus">{{delete_flag_chk}}</td>';
newtrtag += '<td class="releaseDate">{{re_release_ymd}}</td>';
newtrtag += '</tr>';
$("#list_body").append(newtrtag);
整个tbody代码就像这样我要添加它:
<tbody id="list_body">
{% set stock_count = 0 %}
{% for row in release_stock_list %}
<tr class="centertext getData">
<td class="checkGet" style="padding-left: 20px;"><input class="chkGetData" type="checkbox" name="del_param" value="{{row.stay_ymd}},{{row.allot_number}},{{row.delete_flag}},{{row.re_release_ymd}}"></td>
<input type="hidden" id="quantity{{stock_count}}" name="quantity{{stock_count}}" value="{{row.allot_number}}">
<input type="hidden" name="save[{{stock_count}}]" value="{{row.stay_ymd}},{{row.allot_number}},{{row.delete_flag}},{{row.re_release_ymd}}">
{% set delete_flag_val = '0'%}
{% if row.delete_flag %}
{% set delete_flag_val = '1' %}
{% else%}
{% endif %}
<input type="hidden" id="delflag{{stock_count}}" name="delflag{{stock_count}}" value="{{delete_flag_val}}">
<input type="hidden" id="rerel{{stock_count}}" name="rerel{{stock_count}}" value="{{row.re_release_ymd}}">
<td class="colDate">{{row.stay_ymd}}</td>
<td class="colAmount">{{row.allot_number}}</td>
{% set delete_flag_chk = "" %}
{% if row.delete_flag == True %}
{% set delete_flag_chk = "Released" %}
{% else%}
{% set delete_flag_chk = "Unreleased" %}
{% endif %}
<td class="colStatus">{{delete_flag_chk}}</td>
<td class="releaseDate">{{row.re_release_ymd}}</td>
{% set stock_count = stock_count + 1 %}
</tr>
{% endfor %}
</tbody>
感谢您的帮助。