You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, it's a very interesting project!
I was curious how deepdash is used here and I suggest to use findValueDeep method here
instead of eachDeep, because findDeep will stop on first found value, while eachDeep will not (until you will ask it)
new code(not tested) may look like
// get the data for the id in the route param if there is oneexportconstgetItemWithId=(data,id)=>findValueDeep(data,{ id });
note that lodash's iteratee is supported so you can also make a code a bit shorter.
The text was updated successfully, but these errors were encountered:
@YuriGor Thank you for checking Remake out, I'm so happy you find it interesting!
I tried findValueDeep, but it didn't give the result expected.
I need the function to return the parent object, not just the value itself
Also, the code you sent doesn't work as expected, I think it maybe should be: export const getItemWithId = (data, id) => findValueDeep(data, (val, key) => key === "id" && val === id); because the second argument needs to be a function, right?
Anyways, here's the code that works better for me, using findDeep instead:
const getItemWithId = (data, id) => {
const info = _.findDeep(obj, (val, key) => key === "id" && val === id);
if (info && info.parent) {
return info.parent;
}
};
Hi @panphora!
this issue is 2 years old - like a "hello" from previous life for me, thank you for reply :)
Yes your approach is valid, and my fault was - I left default options unchanged.
Correct suggestion from me should be: export const getItemWithId = (data, id) => findValueDeep(data, { id }, {leavesOnly:false});
Second argument may be not only function but also query in the form string, array or object,
as supported by Lodash iteratee (I just use Lodash iteratee internally)
Hi, it's a very interesting project!
I was curious how deepdash is used here and I suggest to use findValueDeep method here
instead of eachDeep, because findDeep will stop on first found value, while eachDeep will not (until you will ask it)
new code(not tested) may look like
note that lodash's iteratee is supported so you can also make a code a bit shorter.
The text was updated successfully, but these errors were encountered: