我想发布解决方案,以防有人需要。示例代码转换 Devx 网格过滤器并创建一组对象来构建查询。
<script>
var t = [
["city","=","DEMING"],[["city","=","DEMING"],"or",["city","=","BLAIR"]],[[["city","=","DEMING"],"or",["city","=","BLAIR"]],"and",["state","=","NM"]],[[["city","=","DEMING"],"or",["city","=","BLAIR"]],"and",["state","=","NM"],"and",[["zip","=","68023"],"or",["zip","=","68008-0098"]]],
[[["fullName","=","BRIGETTE ROOT"],"or",["fullName","=","CHRISTOPHER COLUMBUS"],"or",["fullName","=","HALEY JOEL OSMENT"]],"and",["!",["city","=","BLAIR"]]]];
function buildflat(o,e)
{
let flat = o.flat();
for(let j=0 ; j < flat.length;j++)
{
if(Array.isArray(flat[j])) {
buildflat(flat[j],e);
} else {
if(flat[j] === '!') {
flat[j+1][1] = flat[j] + flat[j+1][1];
} else {
e.push(flat[j]);
}
}
}
}
function buildPairs(e) {
let pairs = [];
for(let i=0; i < e.length;i+=4)
{
pairs.push([e[i], e[i+1],e[i+2]]);
}
return pairs;
}
function groupPairs(p)
{
let groupmap = {};
p.map((e) => {
if(groupmap[e[0]] === undefined)
{
groupmap[e[0]] = [e];
}
else {
groupmap[e[0]].push(e);
}
});
return groupmap;
}
for(let i =0 ; i < t.length;i++)
{
let expression = [];
buildflat(t[i],expression);
console.log(groupPairs(buildPairs(expression)));
}
</script>