查找表中的重复行 [英] Find duplicated rows in a table

查看:89
本文介绍了查找表中的重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有这样的表的小型应用程序:

I have a small application with tables like this:

<tr>
<td><img class='DeleteButton' alt=delete src='images/delete_icon.png'/></td>
<td class='toHide'>some Data</td>
<td class='toHide'>some Data</td>
<td class='toHide'>some Data</td>
<td>some Data</td>
<td class='toHide'>some Data</td>
<td>some Data</td>
<td>some Data</td>
<td class='toHide'>some Data</td>
<td class='toHide'>some Data</td>
<td class='toHide'>some Data</td>
<td class='toHide'>some Data</td>
</tr>

当我在表中添加新数据时,我会创建一个包含建议"的列表-其他数据表中的数据.

When I add new data in the table, I create a list with "suggestions" - data from the other data tables.

但是,如果我有3个表(A,B,C),并且某些数据(D)在A和B中,并且当我想将D添加到C中时,在建议列表中有D个两次.

But if I have 3 tables(A,B,C), and some data(D) is in A and B, and when I want to add D to C, in the suggestion list there is D twice.

那么我如何在表中查找重复的行,以及如何以最有效的方式做到这一点?

So how can I find duplicated rows in a table and how to do it the most efficient way?

(只有不带类的td标签才能隐藏)

(only the td-tags without class toHide matters)

到目前为止,我已经使用jQuery来获取建议列表

So far I have used jQuery to get the suggestion list

 $("all the tables").not(myTable).each(function(){
       $(".suggestData table").append($(this).html());
 }

推荐答案

阅读此帖子:

基于帖子,这是一个示例:

Based on the post this is an example:

function removeD(w){
    var seen = {};
    if(w == 'val'){
        $('table tr td').each(function() {
            var txt = $(this).text();
            if (seen[txt])
                $(this).remove();
            else
                seen[txt] = true;
        });
    }else{
        $('table tr td').each(function() {
            var id = $(this).attr('id');
            if (seen[id])
                $(this).remove();
            else
                seen[id] = true;
        });
    }
}

$('#removeID').click(function(){
    removeD('id');
});



$('#removeVal').click(function(){
    removeD('val');
});

小提琴

这篇关于查找表中的重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆