以下のhtmlコードがありました
<ul class="sales_details clearfix">
<li class="blue_disc">
<a id="product_detail" href="">Som stuff</a>
<span id="product_revenue">$45</span>
</li>
</ul>
<input class="update" type="button">
そして私のjquery
コードは
$(document).ready(function () {
$('.update').click(function() {
var array_list = response_list; // I will get response_list from somewhere as list of dictionaries
$.each(array_list, function (i, item) {
href = "/products/" + item.products__id + "/"
$('#product_detail').attr('href', href).html(item.products__name);
$('#product_revenue').html(item.revenue);
});
});
});
したがって、上記のhtmlおよびjqueryコードから、li element
withクラスblue_disc
が更新されますが、値がオーバーライドされ、その結果、1つのレコードのみを次のように表示できますli
たとえば、私はarray_list
以下のようにしています:
[{'products__name':'One', 'revenue':'45'},
{'products__name':'two', 'revenue':'32'},
{'products__name':'three', 'revenue':'35'}]
データのあるli
要素は1 つしか表示できませんが、product__name : three
だから私がやりたいことは
- 最初に
li element
withクラスを削除blue_disc
します(デフォルトでデータを表示しているため) - 上記の詳細と同様に、li 要素を作成します。
ではどうすれば
li element
クラスで を削除するul
上記のwith クラスの直後に要素を更新するにはどうすればよいsales_details
ですか?