forked from verdnatura/salix-front
refs #6280 feat: deepFind as composable
This commit is contained in:
parent
20835471a3
commit
84b53131c7
|
@ -1,4 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { deepFind } from 'src/composables/deepFind';
|
||||||
import { ref, toRefs, computed, watch } from 'vue';
|
import { ref, toRefs, computed, watch } from 'vue';
|
||||||
const emit = defineEmits(['update:modelValue', 'update:options']);
|
const emit = defineEmits(['update:modelValue', 'update:options']);
|
||||||
|
|
||||||
|
@ -51,20 +52,7 @@ function setOptions(data) {
|
||||||
myOptions.value = JSON.parse(JSON.stringify(data));
|
myOptions.value = JSON.parse(JSON.stringify(data));
|
||||||
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
|
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
|
||||||
}
|
}
|
||||||
function deepFind(obj, path) {
|
|
||||||
var paths = path.split('.')
|
|
||||||
, current = obj
|
|
||||||
, i;
|
|
||||||
|
|
||||||
for (i = 0; i < paths.length; ++i) {
|
|
||||||
if (current[paths[i]] == undefined) {
|
|
||||||
return undefined;
|
|
||||||
} else {
|
|
||||||
current = current[paths[i]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
setOptions(options.value);
|
setOptions(options.value);
|
||||||
const filter = (val, options) => {
|
const filter = (val, options) => {
|
||||||
const search = val.toString().toLowerCase();
|
const search = val.toString().toLowerCase();
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
export async function deepFind(obj, path) {
|
||||||
|
const keys = path.split('.');
|
||||||
|
let current = obj;
|
||||||
|
|
||||||
|
for (const key of keys) {
|
||||||
|
if (current[key] !== undefined) {
|
||||||
|
current = current[key];
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return current;
|
||||||
|
}
|
Loading…
Reference in New Issue