0

いくつかのコンテンツを含むテーブル行を格納する変数があります。%%LIKE%% アプローチを使用してその文字列を特定の用語で検索し、見つかった場合は、フィルタリングされた行のみを含む新しい変数にこの html 行を追加したいと思います。可能であれば、大文字と小文字を区別しない検索を希望します。

これまでのところ、次のようなものがありますが、うまくいかないようです:

// current list
var thisBlock = '<tr><td>Some content</td></tr><tr><td>Some other content</td></tr><tr><td>Even more content</td></tr>';

// new list
var thisList;

// phrase to be found
var thisValue = 'Some';

// filter
var thisItems = $(thisBlock).find("tr:contains('" + thisValue + "')");

// loop to append the found rows
if (thisItems !== '' && typeof thisItems !== 'undefined') {
    $.each(thisItems, function() {
        thisList += $(this).clone().wrap('<div>').parent().html();
    });
}

問題はフィルター部分にあるようで、他の方法でそれを行う方法がわかりません。

4

1 に答える 1

1

これを試して:

var thisItems = $('<table>'+thisBlock+'</table>').find("tr:contains('" + thisValue + "')");

ラッピング テーブル タグがないと、ルート ノードがないため、jQuery がそれを有効なタグと見なすとは思えません。

更新: 次のコードは、一致する各行をテーブル #outTab に追加するために機能しています。それを使用して、希望する場所に到達できますか?

<table id="outTab"/>

<script type="text/javascript">
// current list
var thisBlock = '<table><tr><td>Some content</td></tr><tr><td>Some other content</td></tr><tr><td>Even more content</td></tr></table>';

// new list
var thisList;

// phrase to be found
var thisValue = 'Some';

// filter
var thisItems = $(thisBlock).find("tr:contains('" + thisValue + "')");

// loop to append the found rows
if (thisItems !== '' && typeof thisItems !== 'undefined') {
    $.each(thisItems, function(){
        console.log( this );
        $('#outTab').append(this);
    });
    console.log(thisItems);
}
</script>
于 2012-12-30T16:04:41.763 に答える