Q: How to override property lookup logic (support fields with dots) #2653
Replies: 4 comments
-
two nested objects is really different from a key with a dot in the name, and it can lead to ambiguous cases when you want to resolve nested objects. Like here: let obj3 = {
main: {
temp: 280
},
'main.temp': 260
}; So what would you expect to get when evaluating What you maybe could do is pre-process your scope: replace objects with a dot in the name with nested objects. I.e. replace |
Beta Was this translation helpful? Give feedback.
-
Well, yeah, agree it's not very straightforward, that's because I'm asking about customization and don't expect the lib supports this case by default. In my case I have several data feeds (arrays of object, possibly nested), that I want to join. For this, I flatten them into array-like maps, like this: // input
// output
I'm doing this as I have another feed with a foreign key:
and a result feed will be:
so I don't have any ambiguity, the expr I understand that there're workarounds, e.g. I can possible unwind it back to nested objects:
or try to join them without flattening. But there could be other reason for flattening so I wanted to investigate all my options. |
Beta Was this translation helpful? Give feedback.
-
I understand your use case. I agree that this is a quite specific use case so it makes sense to keep this as a solution (could be a plugin or simply a snippet) separate from mathjs. I think the most straightforward solution is what you're proposing: do some flattening and merging beforehand yourself to mold the data in the structure that you want to have to expose it inside the expression editor. |
Beta Was this translation helpful? Give feedback.
-
The solution I found for a similar problem was to wrap the object like this:
|
Beta Was this translation helpful? Give feedback.
-
Hi!
I wonder is it possible to override the logic of fields navigation.
For example, if I want instead of normal navigation of nested object also support fields with dots in their names.
Here's an example, two objects, obj1 - with a nested value, obj2 - with a dot in a field's name.
I'd expect the expression "main.temp" works in both cases.
Works:
Doesn't (throws 'Undefined symbol main'):
Beta Was this translation helpful? Give feedback.
All reactions