下面是我嘗試做的原型。連接jQuery對象
var entry_set = $;
// start to loop data
for([])
{
// create HTML element to represent that data
$('<div></div>')
.data([])
.addClass([])
.on([])
.insertAfter(entry_set);
}
// modify DOM only once all the entries are consolidated to a single jQuery object
entry_set.appendTo('.entries');
評論說這一切。簡而言之 - 這個想法是在插入數據時只修改文檔DOM一次。我通常會使用HTML字符串方法(簡單地使用字符串連接相同的結構),但是我感興趣的是,是否有類似的東西也可以。
[合併兩個jQuery選擇]可能的重複(http://stackoverflow.com/questions/2400797/merging-two-jquery-selections) –
不是重複的,因爲我沒有初始「選擇」,這是主要問題。 – Gajus
然後創建一個空的選擇:'var entry_set = $()'。另請參見[獲取空的JQuery對象](http://stackoverflow.com/questions/897331/getting-an-empty-jquery-object) –