I have below function.
compare: function (filterObj, sourceObj, fullMatch) {
if (!filterObj) {
return true;
}
var filterKeys = Object.keys(filterObj);
var match = fullMatch;
for (var i = 0, len = filterKeys.length; i < len; i++) {
var key = filterKeys[i];
var value = filterObj[key];
var isKeyInsourceObj = sourceObj.hasOwnProperty(key);
var isEqual = value === "*" || value === sourceObj[key];
var issourceObjPropArr = Array.isArray(sourceObj[key]);
var isValueArr = value === "*" || Array.isArray(value);
if (!fullMatch && isKeyInsourceObj) {
if (isEqual) {
return true;
}
if (issourceObjPropArr && sourceObj[key].indexOf(value) !== -1) {
return true;
}
} else
if (fullMatch && isKeyInsourceObj) {
var inArr = issourceObjPropArr && (sourceObj[key].indexOf(value) !== -1 || (isValueArr && App.Utils.findOne(sourceObj[key], value)));
if (!isEqual && !inArr) {
match = false;
}
}
else {
match = false;
}
}
return match;
},
This is general standard function ,which could be use for anything.
I am trying to get solution when filterObj is category. Now in above code * meaning it covers all types of category (unknown, person, thing, contact, etc).
What I want in addition : I am trying to get category which is not unknown,null, undefined but person, thing,contact.
Note : filterObj has **category, OON, not tracked**,
sourceObj is json which has information about element including filterObj.
This function should be define as general/standard function which could be use anywhere.