0
我創建了一個過濾器,僅顯示包含td
的行,並且從下拉列表中選擇值。過濾器工作正常第一次,但第二次我運行它,所有行消失,我不知道爲什麼。 這是我的過濾器:表上的jquery過濾器第一次工作,但之後隱藏所有行
$(document).ready(function(){
$('select[name=selectedName]').change(function() {
$('tr').filter(function() {
return $(this).find('td.userName').filter(function() {
return $(this).text().indexOf($('select[name=selectedName]').val()) == -1;
}).length;
}).hide();
});
});
下拉:
$query = "SELECT user_name FROM users";
$result = mysql_query($query); ?>
<select name="selectedName" id="userSelected">
<option value="" disabled selected>user name</option>
<?php while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
<option value="<?php echo $line['user_name'];?>">
<?php echo $line['user_name'];?>
</option>
<?php } ?>
</select>
和表的最後創作:
<table class="table table-bordered table-hover" ng-controller="tableCtrl">
<thead>
<th>user name</th>
<th>script name</th>
<th>cron format<span class="glyphicon glyphicon-question-sign"></span></th>
<th>schedule last update</th>
<th>next execution time</th>
<th>script exec</th>
</thead>
<tbody ng-repeat="(user_id,script_id) in data">
<tr ng-repeat="(script_id, cron_format) in script_id">
<td class="userName">{{user(user_id)}}</td>
<td class="scriptName">{{script(script_id)}}</td>
<td class="cronFormat"><span contenteditable="true" ng-repeat="l in letters(cron_format) track by $index">{{l}}</span></td>
<td>{{compare(user_id,script_id,cron_format)[0]}}</td> <!--[0] represents scheduler last update-->
<td>{{compare(user_id,script_id,cron_format)[1]}}</td> <!--[1] represents next execution time-->
<td>{{compare(user_id,script_id,cron_format)[2]}}</td> <!--[2] represents script_exec-->
</tr>
</tbody>
</table>
任何想法爲什麼會發生?感謝您的幫助......
UPDATE
我加入$('tr').show();
和功能,除了工作,我怎麼能在下拉菜單中增加價值來顯示所有的表/取消過濾器?
好點:)...我編輯了我的問題...解決方案仍然無法正常工作... – user3194267 2015-02-11 22:38:31
在調用'.filter()'調用之前調用'.show()'方法。 – 2015-02-11 22:43:21