#14679 closed enhancement (fixed)
Add the ability to use functions in queries for SimpleQueryEngine
Reported by: | Tom Trenka | Owned by: | kriszyp |
---|---|---|---|
Priority: | high | Milestone: | 1.8 |
Component: | Data | Version: | 1.7.1 |
Keywords: | SimpleQueryEngine | Cc: | |
Blocked By: | Blocking: |
Description
I recently had a need to be able to use comparison functions in a query for various (mostly Memory) stores...to do this, I made the following mod in SimpleQueryEngine?.js, starting at line 55 (of 1.7):
case "object": case "undefined": var queryObject = query; query = function(object){ for(var key in queryObject){ var required = queryObject[key]; if(required && required.test){ if(!required.test(object[key])){ return false; } } else if(typeof(required) == "function"){ if(!required(object[key], object)){ return false; } } else if(required != object[key]){ return false; } } return true; }; break;
The idea is that you can use a function of the signature (object[key], object) to return a value (probably boolean). So you could have a store with an object set that has the following signature:
{ order, name, description, foo }
...and then do a query against it like so:
query = { name: /^A*/, order: function(data, obj){ return data < obj.foo } };
Change History (2)
comment:1 Changed 9 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 Changed 9 years ago by
Component: | General → Data |
---|
Note: See
TracTickets for help on using
tickets.
Fixed with [27679], not sure why it isn't showing up.