From b61fa9cee5da265faffeebe1f687ed83d07d3f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87etin?= <69278826+cetincakiroglu@users.noreply.github.com> Date: Wed, 10 Jan 2024 17:56:55 +0300 Subject: [PATCH] Fixed #14319 --- src/app/components/dropdown/dropdown.ts | 4 +- src/app/components/utils/objectutils.ts | 51 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/app/components/dropdown/dropdown.ts b/src/app/components/dropdown/dropdown.ts index 0db7a007900..17de2b6d81a 100755 --- a/src/app/components/dropdown/dropdown.ts +++ b/src/app/components/dropdown/dropdown.ts @@ -693,7 +693,9 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV return options; } set options(val: any[] | undefined) { - this._options.set(val); + if (!ObjectUtils.deepEquals(val, this._options())) { + this._options.set(val); + } } /** * Callback to invoke when value of dropdown changes. diff --git a/src/app/components/utils/objectutils.ts b/src/app/components/utils/objectutils.ts index e1c0c191fd0..95d169637d6 100644 --- a/src/app/components/utils/objectutils.ts +++ b/src/app/components/utils/objectutils.ts @@ -226,4 +226,55 @@ export class ObjectUtils { return item; } + + public static deepEquals(a, b) { + if (a === b) return true; + + if (a && b && typeof a == 'object' && typeof b == 'object') { + var arrA = Array.isArray(a), + arrB = Array.isArray(b), + i, + length, + key; + + if (arrA && arrB) { + length = a.length; + if (length != b.length) return false; + for (i = length; i-- !== 0; ) if (!this.deepEquals(a[i], b[i])) return false; + + return true; + } + + if (arrA != arrB) return false; + + var dateA = a instanceof Date, + dateB = b instanceof Date; + + if (dateA != dateB) return false; + if (dateA && dateB) return a.getTime() == b.getTime(); + + var regexpA = a instanceof RegExp, + regexpB = b instanceof RegExp; + + if (regexpA != regexpB) return false; + if (regexpA && regexpB) return a.toString() == b.toString(); + + var keys = Object.keys(a); + + length = keys.length; + + if (length !== Object.keys(b).length) return false; + + for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; + + for (i = length; i-- !== 0; ) { + key = keys[i]; + if (!this.deepEquals(a[key], b[key])) return false; + } + + return true; + } + + return a !== a && b !== b; + } }