From 18da23530b54abd198fbf19e0e68f3776482e5dc Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 9 Nov 2022 16:47:36 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/xml/ObjectNavigator.js | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/server/core/xml/ObjectNavigator.js b/server/core/xml/ObjectNavigator.js index b2331f5..aa39057 100644 --- a/server/core/xml/ObjectNavigator.js +++ b/server/core/xml/ObjectNavigator.js @@ -1,9 +1,6 @@ class ObjectNavigator { constructor(raw = null) { - if (Array.isArray(raw)) - this.raw = raw; - else - this.raw = [raw]; + this.raw = raw; } makeSelector(selector) { @@ -39,34 +36,30 @@ class ObjectNavigator { let raw = this.raw; for (const s of selector) { if (s.name) { - raw = raw[0]; if (typeof(raw) === 'object' && !Array.isArray(raw)) raw = raw[s.name]; else raw = null; + } - if (raw !== null && !s.last) { - if (Array.isArray(raw)) - raw = raw[s.index]; - else if (s.index > 0) - raw = null; - } - } else { - raw = raw[s.index]; + if (raw !== null && !s.last) { + if (Array.isArray(raw)) + raw = raw[s.index]; + else if (s.index > 0) + raw = null; } if (raw === undefined || raw === null) { raw = null; break; } - - if (!Array.isArray(raw)) - raw = [raw]; } if (raw === null) return null; + raw = (Array.isArray(raw) ? raw : [raw]); + const result = []; for (const r of raw) result.push(new ObjectNavigator(r)); @@ -84,7 +77,7 @@ class ObjectNavigator { } get value() { - return (this.raw.length ? this.raw[0] : null); + return this.raw; } text(selector = '') {