我能够动态追加表行,但在嵌入值时遇到问题。
我正在使用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>
谢谢您的帮助。