Javascript 带有多个复选框的HTML表过滤器
我有一个javascript函数,它标识所有复选框,并创建一个变量以在过滤器的return语句中使用,目标是只显示那些选中了相应复选框的行。如果我键入返回函数(在下面的代码中注释掉),我将得到所需的结果。但是,内容与键入的返回语句相同的变量“filter_list”不起作用 要么我错过了什么,要么我想做的事做不到。正在寻找对我的代码的修复或基于所做选择的更好的过滤方式Javascript 带有多个复选框的HTML表过滤器,javascript,jquery,Javascript,Jquery,我有一个javascript函数,它标识所有复选框,并创建一个变量以在过滤器的return语句中使用,目标是只显示那些选中了相应复选框的行。如果我键入返回函数(在下面的代码中注释掉),我将得到所需的结果。但是,内容与键入的返回语句相同的变量“filter_list”不起作用 要么我错过了什么,要么我想做的事做不到。正在寻找对我的代码的修复或基于所做选择的更好的过滤方式 script.js $(document).ready(function(){ var markedLocations
script.js
$(document).ready(function(){
var markedLocations = document.getElementsByName('location_filter');
var i = 0
var filter_list = ''
for (var location of markedLocations) {
if (location.checked){
if (i > 0){
var filter_list = filter_list.concat(' || $(this).find("td").eq(2).text() == "' + location.value + '"')
}else{
var filter_list = '$(this).find("td").eq(2).text() == "' + location.value + '"'
}
var i = i + 1
}else{
var i = i
}
}
(function ($) {
$('.searchable tr').hide();
$('.searchable tr').filter(function(){
console.log(filter_list)
return filter_list
// return $(this).find("td").eq(2).text() == "H3A"
// || $(this).find("td").eq(2).text() == "H5A"
// || $(this).find("td").eq(2).text() == "H5B"
// || $(this).find("td").eq(2).text() == "H6A"
// || $(this).find("td").eq(2).text() == "H6B"
// || $(this).find("td").eq(2).text() == "Backshop"
}).show();
}(jQuery));
});
dashboard.html
工程服务请求仪表板
上次更新:{%now“m-d-Y H:i”%}EDT
{user_info%}中的用户为%
{%如果user.H1A为真%}
H1A|
{%else%}
H1A|
{%endif%}
{%如果user.H1B为真%}
H1B|
{%else%}
H1B|
{%endif%}
{%如果user.H2A为真%}
H2A|
{%else%}
H2A|
{%endif%}
{%如果user.H2B为真%}
H2B|
{%else%}
H2B|
{%endif%}
{%如果user.H3A为真%}
H3A|
{%else%}
H3A|
{%endif%}
{%如果user.H3B为真%}
H3B|
{%else%}
H3B|
{%endif%}
{%如果user.H5A为真%}
H5A|
{%else%}
H5A|
{%endif%}
{%如果user.H5B为真%}
H5B|
{%else%}
H5B|
{%endif%}
{%如果user.H6A为真%}
H6A|
{%else%}
H6A|
{%endif%}
{%如果user.H6B为真%}
H6B|
{%else%}
H6B|
{%endif%}
{%如果user.backshop为True%}
后座
{%else%}
后座
{%endif%}
{%endfor%}
按指定的工作站(机库)进行筛选
电子自旋共振#
地位
位置
飞机
ESR科目
NRC日期
ESR日期
ESR到期日
RTS日期
{请求%中的请求为%}
{{request.status}
{{request.location}
{{request.airpair}}
{{request.subject}}
{{request.NrcDate}日期:“m-d-Y”}
{{请求.时间戳}日期:“m-d-Y H:i”}EDT
{{请求.截止日期}日期:“m-d-Y”}
{%if request.location=='Backshop%}
不适用
{%else%}
{请求.发布日期}日期:“m-d-Y H:i”}EDT
{%endif%}
{%empty%}
无活动请求
{%endfor%}
生成的HTML
工程服务请求仪表板
最后更新:05-04-2021 12:43美国东部时间
H1A|
dashboard.html
<div class="table header mb-2">
<h3 class="header mb-2 text-center">Engineering Service Request Dashboard</h3>
<h6 class="header mb-2 text-center" id="current-time">Last Update: {% now "m-d-Y H:i" %} EDT</h6>
<div class="filters">
{% for user in user_info %}
{% if user.H1A is True %}
<label><input value="H1A" id="H1A_filter" name="location_filter" type="checkbox" checked>H1A | </label>
{% else %}
<label><input value="H1A" id="H1A_filter" name="location_filter" type="checkbox">H1A | </label>
{% endif %}
{% if user.H1B is True %}
<label><input value="H1B" id="H1B_filter" name="location_filter" type="checkbox" checked>H1B | </label>
{% else %}
<label><input value="H1B" id="H1B_filter" name="location_filter" type="checkbox">H1B | </label>
{% endif %}
{% if user.H2A is True %}
<label><input value="H2A" id="H2A_filter" name="location_filter" type="checkbox" checked>H2A | </label>
{% else %}
<label><input value="H2A" id="H2A_filter" name="location_filter" type="checkbox">H2A | </label>
{% endif %}
{% if user.H2B is True %}
<label><input value="H2B" id="H2B_filter" name="location_filter" type="checkbox" checked>H2B | </label>
{% else %}
<label><input value="H2B" id="H2B_filter" name="location_filter" type="checkbox">H2B | </label>
{% endif %}
{% if user.H3A is True %}
<label><input value="H3A" id="H3A_filter" name="location_filter" type="checkbox" checked>H3A | </label>
{% else %}
<label><input value="H3A" id="H3A_filter" name="location_filter" type="checkbox">H3A | </label>
{% endif %}
{% if user.H3B is True %}
<label><input value="H3B" id="H3B_filter" name="location_filter" type="checkbox" checked>H3B | </label>
{% else %}
<label><input value="H3B" id="H3B_filter" name="location_filter" type="checkbox">H3B | </label>
{% endif %}
{% if user.H5A is True %}
<label><input value="H5A" id="H5A_filter" name="location_filter" type="checkbox" checked>H5A | </label>
{% else %}
<label><input value="H5A" id="H5A_filter" name="location_filter" type="checkbox">H5A | </label>
{% endif %}
{% if user.H5B is True %}
<label><input value="H5B" id="H5B_filter" name="location_filter" type="checkbox" checked>H5B | </label>
{% else %}
<label><input value="H5B" id="H5B_filter" name="location_filter" type="checkbox">H5B | </label>
{% endif %}
{% if user.H6A is True %}
<label><input value="H6A" id="H6A_filter" name="location_filter" type="checkbox" checked>H6A | </label>
{% else %}
<label><input value="H6A" id="H6A_filter" name="location_filter" type="checkbox">H6A | </label>
{% endif %}
{% if user.H6B is True %}
<label><input value="H6B" id="H6B_filter" name="location_filter" type="checkbox" checked>H6B | </label>
{% else %}
<label><input value="H6B" id="H6B_filter" name="location_filter" type="checkbox">H6B | </label>
{% endif %}
{% if user.backshop is True %}
<label><input value="Backshop" id="backshop_filter" name="location_filter" type="checkbox" checked>Backshop</label>
{% else %}
<label><input value="Backshop" id="backshop_filter" name="location_filter" type="checkbox">Backshop</label>
{% endif %}
{% endfor %}
<br>
<label><input id="filter2" type="checkbox" checked>Filter By Assigned Work Stations (Hangars)</label>
</div>
<table id="table" class="table table-bordered table-striped w-auto mx-auto"
data-toggle="table"
data-search="true"
data-filter-control="true"
data-show-multi-sort="true"
data-show-multi-sort-button="true"
data-show-print="true"
data-show-refresh="true"
data-show-fullscreen="true"
data-filter-control-container="true"
data-show-export="true">
<thead>
<tr class="text-center">
<th data-field="esr" data-sortable="true">ESR #</th>
<th data-field="status" data-filter-control="select">Status</th>
<th data-field="location" data-filter-control="select">Location</th>
<th data-field="aircraft" data-filter-control="select">Aircraft</th>
<th data-field="subject" data-width="35" data-width-unit="%">ESR Subject</th>
<th data-field="nrc_date" data-sortable="true">NRC Date</th>
<th data-field="esr_date" data-sortable="true">ESR Date</th>
<th data-field="esr_due_date" data-sortable="true">ESR Due Date</th>
<th data-field="rts_date" data-sortable="true">RTS Date</th>
</tr>
</thead>
<tbody id="dashboard" class="searchable">
{% for request in requests %}
<tr class="text-center">
<td>
<a href="{% url 'esr_dashboard:esr-detail' request.id %}" class="request_link text-primary" data-id="{{ request.id }}">{{ request.request_number }}</a>
</td>
<td>
{{ request.status }}
</td>
<td>
{{ request.location }}
</td>
<td>
{{ request.aircraft }}
</td>
<td>
{{ request.subject }}
</td>
<td>
{{ request.NrcDate|date:"m-d-Y" }}
</td>
<td>
{{ request.timestamp|date:"m-d-Y H:i" }} EDT
</td>
<td>
{{ request.due_date|date:"m-d-Y" }}
</td>
<td>
{% if request.location == 'Backshop' %}
N/A
{% else %}
{{ request.release_date|date:"m-d-Y H:i" }} EDT
{% endif %}
</td>
{% empty %}
<td colspan=9>
<p class="text-center">No active requests</p>
</td>
{% endfor %}
</tr>
</tbody>
</table>
Generated HTML
<div class="table header mb-2">
<h3 class="header mb-2 text-center">Engineering Service Request Dashboard</h3>
<h6 class="header mb-2 text-center" id="current-time">Last Update: 05-04-2021 12:43 EDT</h6>
<div class="filters">
<label><input value="H1A" id="H1A_filter" name="location_filter" type="checkbox">H1A | </label>
<label><input value="H1B" id="H1B_filter" name="location_filter" type="checkbox">H1B | </label>
<label><input value="H2A" id="H2A_filter" name="location_filter" type="checkbox">H2A | </label>
<label><input value="H2B" id="H2B_filter" name="location_filter" type="checkbox">H2B | </label>
<label><input value="H3A" id="H3A_filter" name="location_filter" type="checkbox" checked="">H3A | </label>
<label><input value="H3B" id="H3B_filter" name="location_filter" type="checkbox">H3B | </label>
<label><input value="H5A" id="H5A_filter" name="location_filter" type="checkbox" checked="">H5A | </label>
<label><input value="H5B" id="H5B_filter" name="location_filter" type="checkbox" checked="">H5B | </label>
<label><input value="H6A" id="H6A_filter" name="location_filter" type="checkbox" checked="">H6A | </label>
<label><input value="H6B" id="H6B_filter" name="location_filter" type="checkbox" checked="">H6B | </label>
<label><input value="Backshop" id="backshop_filter" name="location_filter" type="checkbox" checked="">Backshop</label>
</div>
<table id="table" class="table table-bordered table-striped w-auto mx-auto table-hover" data-toggle="table" data-search="true" data-filter-control="true" data-show-multi-sort="true" data-show-multi-sort-button="true" data-show-print="true" data-show-refresh="true" data-show-fullscreen="true" data-filter-control-container="true" data-show-export="true">
<thead style=""><tr class="text-center">
<th style="" data-field="esr"><div class="th-inner sortable both">ESR #</div><div class="fht-cell"></div></th>
<th style="" data-field="status"><div class="th-inner ">Status</div><div class="fht-cell"></div></th>
<th style="" data-field="location"><div class="th-inner ">Location</div><div class="fht-cell"></div></th>
<th style="" data-field="aircraft"><div class="th-inner ">Aircraft</div><div class="fht-cell"></div></th>
<th style="width: 35%; " data-field="subject"><div class="th-inner ">ESR Subject</div><div class="fht-cell"></div></th>
<th style="" data-field="nrc_date"><div class="th-inner sortable both">NRC Date</div><div class="fht-cell"></div></th>
<th style="" data-field="esr_date"><div class="th-inner sortable both">ESR Date</div><div class="fht-cell"></div></th>
<th style="" data-field="esr_due_date"><div class="th-inner sortable both">ESR Due Date</div><div class="fht-cell"></div></th>
<th style="" data-field="rts_date"><div class="th-inner sortable both">RTS Date</div><div class="fht-cell"></div></th></tr>
</thead>
<tbody id="dashboard" class="searchable">
<tr class="text-center" data-index="0" style="">
<td><a href="/esr_dashboard/request_details/570/" class="request_link text-primary" data-id="570">210012</a></td>
<td>new_status</td>
<td>H5B</td><td>N8652B</td>
<td style="width: 35%; ">TEST REFRESH SETTING</td>
<td>05-03-2021</td>
<td>05-03-2021 23:35 EDT</td>
<td>05-03-2021</td>
<td>04-30-2021 20:00 EDT</td>
</tr>
<tr class="text-center" data-index="1" style="">
<td><a href="/esr_dashboard/request_details/569/" class="request_link text-primary" data-id="569">210011</a></td>
<td>in_work_EG</td>
<td>H5B</td><td>N8652B</td>
<td style="width: 35%; ">Plane broke</td>
<td>05-02-2021</td>
<td>05-01-2021 20:01 EDT</td>
<td>05-14-2021</td>
<td>04-30-2021 20:00 EDT</td>
</tr>
<tr class="text-center" data-index="2" style="">
<td><a href="/esr_dashboard/request_details/568/" class="request_link text-primary" data-id="568">210010</a></td>
<td>new_status</td><td>H3B</td>
<td>N8614M</td>
<td style="width: 35%; ">Plane broke</td>
<td>05-01-2021</td>
<td>05-01-2021 17:28 EDT</td>
<td>05-01-2021</td>
<td>04-28-2021 03:00 EDT</td>
</tr>
<tr class="text-center" data-index="3" style="">
<td><a href="/esr_dashboard/request_details/567/" class="request_link text-primary" data-id="567">210009</a></td>
<td>in_work_EG</td><td>H3B</td><td>N8614M</td>
<td style="width: 35%; ">Fuselage skin dent at STA 540 above S-12L</td>
<td>05-01-2021</td>
<td>05-01-2021 17:05 EDT</td>
<td>05-14-2021</td>
<td>04-28-2021 03:00 EDT</td>
</tr>
<tr class="text-center" data-index="4" style="">
<td><a href="/esr_dashboard/request_details/566/" class="request_link text-primary" data-id="566">210008</a></td>
<td>new_status</td>
<td>H6A</td>
<td>168764</td>
<td style="width: 35%; ">BUNO 168764 - Alternate Procedure Request</td>
<td>04-29-2021</td>
<td>04-30-2021 13:16 EDT</td>
<td>05-07-2021</td>
<td>08-05-2021 23:00 EDT</td>
</tr>
<tr class="text-center" data-index="5" style="">
<td><a href="/esr_dashboard/request_details/565/" class="request_link text-primary" data-id="565">210007</a></td>
<td>new_status</td>
<td>H3B</td>
<td>N8614M</td>
<td style="width: 35%; ">adsafsad</td>
<td>04-30-2021</td>
<td>04-30-2021 09:55 EDT</td>
<td>04-30-2021</td>
<td>04-28-2021 03:00 EDT</td>
</tr>
<tr class="text-center" data-index="6" style="">
<td><a href="/esr_dashboard/request_details/564/" class="request_link text-primary" data-id="564">210006</a></td>
<td>in_work_PROD</td>
<td>Backshop</td>
<td>DoD_P-8A</td>
<td style="width: 35%; ">Spare aileron skin repair - alternate repair part request</td>
<td>04-22-2021</td>
<td>04-29-2021 07:55 EDT</td>
<td>05-07-2021</td>
<td>N/A</td>
</tr>
<tr class="text-center" data-index="7" style="">
<td><a href="/esr_dashboard/request_details/563/" class="request_link text-primary" data-id="563">210005</a></td>
<td>in_work_CUST</td>
<td>H3B</td>
<td>N8664J</td>
<td style="width: 35%; ">Fuselage skin dent at STA 1016+15 below S-17L</td>
<td>04-06-2021</td>
<td>04-28-2021 23:58 EDT</td>
<td>04-23-2021</td>
<td>04-09-2021 12:00 EDT</td>
</tr>
<tr class="text-center" data-index="8" style="">
<td><a href="/esr_dashboard/request_details/562/" class="request_link text-primary" data-id="562">210004</a></td>
<td>new_status</td>
<td>H5B</td>
<td>N8652B</td>
<td style="width: 35%; ">asdfasd</td>
<td>04-06-2021</td>
<td>04-28-2021 23:58 EDT</td>
<td>04-21-2021</td>
<td>04-30-2021 20:00 EDT</td>
</tr>
<tr class="text-center" data-index="9" style="">
<td><a href="/esr_dashboard/request_details/561/" class="request_link text-primary" data-id="561">210003</a></td>
<td>new_status</td>
<td>H5B</td>
<td>N8652B</td>
<td style="width: 35%; ">sadfas</td>
<td>04-16-2021</td>
<td>04-28-2021 23:57 EDT</td>
<td>04-30-2021</td><td>04-30-2021 20:00 EDT</td>
</tr>
<tr class="text-center" data-index="10" style="">
<td><a href="/esr_dashboard/request_details/560/" class="request_link text-primary" data-id="560">210002</a></td>
<td>new_status</td>
<td>H3B</td>
<td>N8614M</td>
<td style="width: 35%; ">asdfsad</td>
<td>04-28-2021</td>
<td>04-28-2021 23:56 EDT</td>
<td>04-01-2021</td>
<td>04-28-2021 03:00 EDT</td>
</tr>
<tr class="text-center" data-index="11" style="">
<td><a href="/esr_dashboard/request_details/559/" class="request_link text-primary" data-id="559">210001</a></td>
<td>new_status</td>
<td>H3B</td>
<td>N8614M</td>
<td style="width: 35%; ">ABCD</td>
<td>04-28-2021</td>
<td>04-28-2021 23:52 EDT</td>
<td>04-28-2021</td>
<td>04-28-2021 03:00 EDT</td>
</tr>
</tbody>
</table>
</div>
filter_list = filter_list.concat(' || $(this).find("td").eq(2).text() == "' + location.value + '"');
(function ($) {
$('.searchable tr').hide();
$('.searchable tr').filter(function(){
var res = eval(filter_list);
console.log(res);
return res;
:
: