What's the most efficient way to manage large datasets with Javascript/jQuery in IE?

后端 未结 4 2218
一个人的身影
一个人的身影 2021-02-10 08:05

I have a search that returns JSON, which I then transform into a HTML table in Javascript. It repeatedly calls the jQuery.append() method, once for each row. I have a modern m

4条回答
  •  抹茶落季
    2021-02-10 08:16

    Multiple DOM append operations will kill performance. And you may run into a problem with string immutability as well.

    Keep the data as small as possible (JSON arrays are good), and build the html in script avoiding the javascript string concatenation problem. Append the html values to an array, and then join the array afterwards. Do one DOM append once the html has been created. eg

    var builder = [];
    
    //Inside a loop
    builder.push('');
    builder.push(json.value);
    builder.push('');
    
    //Outside the loop
    $('div').append(builder.join(''));
    

提交回复
热议问题