首页 > 解决方案 > 如何使用条件过滤表中的行

问题描述

<script>
$(document).ready(function() {
$("#tabledivss").hide();
$("#showTable").click(function(event) {
var frmdt = $("#fromDate").val();
var nam = $("#name").val();
$.get('studenttable', function(responseJson) {
if (responseJson != null) {
$("#countrytabless").find("tr:gt(0)").remove();
var table4 = $("#countrytabless");
$.each(responseJson, function(key, value) {
if(nam === "Mithra")
{
var rowNew = $("<tr> <td></td><td></td><td></td><td></td></tr>");
rowNew.children().eq(0).text(value['CODE']);
rowNew.children().eq(1).text(value['Our_ID']);
rowNew.children().eq(2).text(value['Name']);
rowNew.appendTo(table4);
}
});
}
});
});
});
</script>
<select id="name">
<option value="01"> Mithra </option>
<option value="02"> Ravi </option></select>
<table id="tabledivss">
 <tr> 
        <th scope="col">Code</th>
        <th scope="col">ID</th>
        <th scope="col">name</th>
        <th scope="col">Location</th>
</tr></table>

我使用此代码根据下拉列表值过滤行。仅根据 if 条件在行中显示密特拉值。我不知道在获取数据时如何过滤行。

标签: jsonapifilterdrop-down-menufetch

解决方案


推荐阅读