use the data "var" in side "filter"
Does anyone know how do I pass in the data by using "var" inside "filter"? because the "var" inside filter alw default to the filtering array elements. Eg the rules and data as below:
Rules:
{ "filter": [ [ { "min": 1, "max": 1, "value": "a" }, { "min": 2, "max": 2, "value": "b" } ], {"<=":[{"var":"min"},{"var": "input"},{"var": "max"}]} ] }
Data:
{input: 1}
This seems impossible. Did you find proper workaround?
When calling your function on the elements of the array, your context is only that array element. Essentially, there's no lambda capture.
Newer to this library but best way I have found to make this work is to define an additional operator that creates an array with the data as context, so that you can access it within map/filter/etc by making a var lookup into "context" (and can still look up the array element via "elem").
jsonLogic.add_operation('arrayWithContext', function (array) {
const context = this;
return array.map(elem => ({ elem, context }));
});