From 4f847be5c4e1721b4f752faa3716b90543ece304 Mon Sep 17 00:00:00 2001 From: Candid Dauth Date: Tue, 14 Nov 2017 01:39:47 +0100 Subject: [PATCH] Flatten object for filter (fixes #79) Related to issue https://github.com/joewalnes/filtrex/issues/12, filtrex does not support nested properties. --- frontend/common/filter.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/frontend/common/filter.js b/frontend/common/filter.js index 62251c16..2cba5187 100644 --- a/frontend/common/filter.js +++ b/frontend/common/filter.js @@ -114,11 +114,32 @@ const filter = module.exports = { }, prepareObject: function(obj, type) { - obj = $.extend(true, { }, obj); + obj = filter.flattenObject(obj); if(type) obj.type = type.type; return obj; + }, + + flattenObject(data) { + // https://stackoverflow.com/a/19101235/242365 + + var result = {}; + function recurse (cur, prop) { + if(prop) + result[prop] = cur; + + if(Array.isArray(cur)) { + for(var i=0, l=cur.length; i