changes on updateResults, populate by @cervengoc on #781
use string concatenation instead of DOM manipulation at populate. This does gives about a 45% speed boost as measured with chrome v35. Code by @cervengoc on #781
This commit is contained in:
parent
52425f93c8
commit
12e0de21ae
52
select2.js
52
select2.js
@ -919,39 +919,46 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
populate=function(results, container, depth) {
|
populate=function(results, container, depth) {
|
||||||
|
|
||||||
var i, l, result, selectable, disabled, compound, node, label, innerContainer, formatted;
|
var i, l, result, selectable, disabled, compound, node, label, innerContainer, formatted, formattedClass;
|
||||||
|
|
||||||
results = opts.sortResults(results, container, query);
|
results = opts.sortResults(results, container, query);
|
||||||
|
|
||||||
|
// collect the created nodes for bulk append
|
||||||
|
var nodes = [];
|
||||||
for (i = 0, l = results.length; i < l; i = i + 1) {
|
for (i = 0, l = results.length; i < l; i = i + 1) {
|
||||||
|
|
||||||
result=results[i];
|
result=results[i];
|
||||||
|
|
||||||
disabled = (result.disabled === true);
|
disabled = (result.disabled === true);
|
||||||
selectable = (!disabled) && (id(result) !== undefined);
|
selectable = (!disabled) && (id(result) !== undefined);
|
||||||
|
|
||||||
compound=result.children && result.children.length > 0;
|
compound=result.children && result.children.length > 0;
|
||||||
|
|
||||||
node=$("<li></li>");
|
node ="<li class=\"";
|
||||||
node.addClass("select2-results-dept-"+depth);
|
node += "select2-results-dept-" + depth;
|
||||||
node.addClass("select2-result");
|
node += " select2-result";
|
||||||
node.addClass(selectable ? "select2-result-selectable" : "select2-result-unselectable");
|
node+= selectable ? " select2-result-selectable" : " select2-result-unselectable";
|
||||||
if (disabled) { node.addClass("select2-disabled"); }
|
if (disabled)
|
||||||
if (compound) { node.addClass("select2-result-with-children"); }
|
node += " select2-disabled";
|
||||||
node.addClass(self.opts.formatResultCssClass(result));
|
if (compound)
|
||||||
node.attr("role", "presentation");
|
node += " select2-result-with-children";
|
||||||
|
formattedClass = self.opts.formatResultCssClass(result);
|
||||||
|
if (formattedClass != undefined)
|
||||||
|
node += " " + formattedClass;
|
||||||
|
node += "\" role=\"presentation\">";
|
||||||
|
|
||||||
label=$(document.createElement("div"));
|
label = "<div class=\"select2-result-label\"";
|
||||||
label.addClass("select2-result-label");
|
label += " id=\"select2-result-label-" + nextUid() + "\"";
|
||||||
label.attr("id", "select2-result-label-" + nextUid());
|
label += " role=\"option\"";
|
||||||
label.attr("role", "option");
|
label += ">";
|
||||||
|
formatted = opts.formatResult(result, label, query, self.opts.escapeMarkup);
|
||||||
|
if (formatted !== undefined)
|
||||||
|
label += formatted;
|
||||||
|
label += "</div>";
|
||||||
|
|
||||||
formatted=opts.formatResult(result, label, query, self.opts.escapeMarkup);
|
node += label;
|
||||||
if (formatted!==undefined) {
|
node += "</li>";
|
||||||
label.html(formatted);
|
|
||||||
node.append(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// I still used jQuery wrapping for setting "data" below
|
||||||
|
node = $(node);
|
||||||
|
|
||||||
if (compound) {
|
if (compound) {
|
||||||
|
|
||||||
@ -962,9 +969,10 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
}
|
}
|
||||||
|
|
||||||
node.data("select2-data", result);
|
node.data("select2-data", result);
|
||||||
container.append(node);
|
nodes.push(node[0]);
|
||||||
}
|
}
|
||||||
|
// bulk append the created nodes
|
||||||
|
container.append(nodes);
|
||||||
liveRegion.text(opts.formatMatches(results.length));
|
liveRegion.text(opts.formatMatches(results.length));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user