-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arrays with Objects #17
Comments
You could build a custom operaton using dotty's search method and then using that with jsonLogic.add_operation('var_search', function(key){
return dotty.search(this, key); //In custom operations "this" is bound to data
});
var rules = { "and" : [
{"<" : [ { "var" : "temp" }, 110 ]},
{"in" : ["apple", { "var_search" : "pies.*.filling" } ] }
] };
var data = { "temp" : 100, "pies" : [{ "filling" : "apple" }, { "filling" : "cherry" }]};
jsonLogic.apply(rules, data);
// true Does that work? |
Had the same problem. This is a common use case, and should be added to core. @jwadhams thank you for the solution. |
@PaulKruger please see #25 |
Thanks for your example above. I am trying to filter on multiple nested fields. However, it isn't returning any results. Any suggestions?
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I didn't notice whether you had or planned to develop functions that included arrays that contained objects.
So for example if wanted to return true if there is an apple pie in group of pies:
var rules = { "and" : [
{"<" : [ { "var" : "temp" }, 110 ]},
{"==" : [ { "var" : "pies.filling" }, "apple" ] }
] };
var data = { "temp" : 100, "pies" : [{ "filling" : "apple" }, { "filling" : "cherry" }]};
jsonLogic.apply(rules, data);
// true
The text was updated successfully, but these errors were encountered: