Skip to content

Commit

Permalink
fix select: solved performance issue for data() nethod
Browse files Browse the repository at this point in the history
  • Loading branch information
olton committed Jan 31, 2025
1 parent b67836d commit 4836dd6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
11 changes: 10 additions & 1 deletion lib/metro.js
Original file line number Diff line number Diff line change
Expand Up @@ -16107,16 +16107,20 @@
const option2 = $3("<option>").attr("value", val).text(title3 ? title3 : val);
element2.append(option2);
if (selected) {
if (element2[0].multiple) {
} else {
element2.find("option").prop("selected", false);
}
option2.prop("selected", true);
}
this._createOptions();
return this;
},
addOptions: function(values) {
const that = this;
if (!values) {
return this;
}
this.observer.disconnect();
if (Array.isArray(values)) {
$3.each(values, function() {
const o2 = this;
Expand All @@ -16131,6 +16135,11 @@
that.addOption(key, val);
});
}
this._createOptions();
this.observer.observe(element[0], {
childList: true,
subtree: true
});
return this;
},
removeOption: function(val) {
Expand Down
4 changes: 2 additions & 2 deletions lib/metro.js.map

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion source/components/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,15 @@
element.append(option);

if (selected) {
if (element[0].multiple) {
// nothing
} else {
element.find("option").prop("selected", false);
}
option.prop("selected", true);
}

this._createOptions();
// this._createOptions();

return this;
},
Expand All @@ -821,6 +826,8 @@
return this;
}

this.observer.disconnect();

if (Array.isArray(values)) {
$.each(values, function () {
const o = this;
Expand All @@ -836,6 +843,13 @@
});
}

this._createOptions();

this.observer.observe(element[0], {
childList: true,
subtree: true,
})

return this;
},

Expand Down

0 comments on commit 4836dd6

Please sign in to comment.