會先寫一個template用來clone用,
但是發現為何css的呈現都會用最後一筆的樣子
找了clone用法https://api.jquery.com/clone/
也跟他無關,後來發現是自己犯傻了.
原因說明詳見下面範例註解處.
範例
template += ' ';
template += ' ';
template += ' ';
template += '
';
template += ' ';
template += ' ';
template += ' ';
template += ' ';
$template = $(template);
for (i = 0; i < channelItemJson.length; i++) {
var $newItemCol = $template.clone();
$newItemCol.find('img').attr('src', window.itemImgPreUrl + channelItemJson[i]['localCoverPath']);
$newItemCol.find('p').text(channelItemJson[i]['name']);
$newItemCol.find(".channel-item-detail").on("click", {
elements: $newItemCol,
}, handler2ItemDetail);
//$('.search-all-price-group').show();
//this strategy will cause side-effect
//beacuse there are many '.search-all-price-group' class
//this is right
$newItemCol.find('.search-all-price-group').show();
$("#scroll-container").append($newItemCol.fadeIn());
}

