diff --git a/src/utils/AppendOptions.js b/src/utils/AppendOptions.js index c5a54de..2871269 100644 --- a/src/utils/AppendOptions.js +++ b/src/utils/AppendOptions.js @@ -2,14 +2,16 @@ import { Ut } from "./Ut"; export class AppendOptions { - constructor(target, data, opts) { + constructor(target, data, opts) { - opts = opts || {}; + opts = opts || {}; - if (opts.clear) { - this.replaceChildren(); - } + if (opts.clear) { + this.replaceChildren(); + } - Ut.each(Ut.isStr(data) ? JSON.parse(data) : data, (val, id) => target.append(new Option(val, id)) ); - } + Ut.each(Ut.isStr(data) + ? data.replace(/"((?:\\.|[^"\\])*)"\s*:\s*"((?:\\.|[^"\\])*)"/g, (_, rawKey, rawVal) => target.append(new Option(JSON.parse(`"${rawVal}"`), JSON.parse(`"${rawKey}"`) )) ) + : data, (val, id) => target.append(new Option(val, id)) ); + } } \ No newline at end of file