2012-05-12 14 views
0

配列の最後のセル内の不要なオブジェクト:私が解析されたXML列に以下のコードを使用してい

$(this).find("cp_group").each(function() { 
    $("select#comp_1").append('<optgroup label="' + $(this).attr('label') + '"><option>' + $(this).find("cmp").map(function() { 
     return $(this).text(); 
    }).get().join("</option><option>") + $(this).append('</option></optgroup>')); 
});​ 

と私は、各オプショングループの最後のオプションでは、不要な[オブジェクトのオブジェクト]を取得

<select name="comp_1" id="comp_1"> 
<optgroup label="Combat"> 
<option>Arme</option> 
<option>Arts martiaux</option> 
<option>Esquive</option> 
<option>Feinte</option> 
<option>Parade</option> 
<option>Lutte[object Object]</option> 

私はこの[オブジェクトオブジェクト]がどこから来たのか分からず、それを取得したり削除したりすることはできませんでした。 ありがとうございます。

+0

あなたはhttp://jsfiddle.netでバイオリンを作ることはできますか? – gdoron

答えて

2

+ $(this).append(...)から来ています。そのjQueryラッパーを使わずに、+'</option....'の部分だけを必要とします。

1

jQuery、特にappendがどのように機能するか誤解しました。 jQueryで操作するときにマークアップ(主に)を扱っていない場合は、オブジェクト(DOM要素)を扱っています。

これはそれを修正する必要があります

$(this).find("cp_group").each(function() { 
    // Get this entry 
    var $this = $(this); 

    // Create the optgroup 
    var optgroup = $('<optgroup label="' + $this.attr('label') + '">'); 

    // Fill it in 
    $this.find("cmp").each(function() { 
     $("<option>").text($(this).text()).appendTo(optgroup); 
    }); 

    // Append it to the select 
    $("select#comp_1").append(optgroup); 
});​ 
関連する問題