0
0
Fork 0

refs #6280 feat: deepFind as composable

This commit is contained in:
Javier Segarra 2024-01-15 09:22:01 +01:00
parent 20835471a3
commit 84b53131c7
2 changed files with 15 additions and 13 deletions

View File

@ -1,4 +1,5 @@
<script setup>
import { deepFind } from 'src/composables/deepFind';
import { ref, toRefs, computed, watch } from 'vue';
const emit = defineEmits(['update:modelValue', 'update:options']);
@ -51,20 +52,7 @@ function setOptions(data) {
myOptions.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);
const filter = (val, options) => {
const search = val.toString().toLowerCase();

View File

@ -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;
}