我已经成功创建了一个:
...但是在很多努力和搜索之后,我还没有能够设置Filterbar模块来执行服务器端过滤。
我使用了< filterSetupQuery'从JSON中取出信息(在客户端上)并附加到获取URL以获取非常基本的过滤器,但是对于复杂的过滤器,在服务器上基于Java的控制器中处理JSON似乎更有意义。
这个Java类和FlexJson反序列化器甚至会是什么样子? 是否有人有服务器端过滤的参考实现,甚至是一个示例来说明如何在Java中反序列化此对象?
这是一个简单的JSON对象,它被发送回控制器:
{ "op":"and",
"data":[{ "op":"or",
"data":[{"op":"contain","data":[{"op":"string","data":"1","isCol":true},
{"op":"string","data":"john"}]},
{"op":"contain","data":[{"op":"string","data":"2","isCol":true},
{"op":"string","data":"john"}]},
{"op":"contain","data":[{"op":"string","data":"3","isCol":true},
{"op":"string","data":"john"}]},
{"op":"contain","data":[{"op":"string","data":"4","isCol":true},
{"op":"string","data":"john"}]}
]}]}
非常感谢任何帮助! 谢谢 克里斯
答案 0 :(得分:0)
您可以查看gridx源代码..在\ tests \ test_grid_filter_serverside.html
下filterSetupFilterQuery: function(expr){
var toExpr = function(expr){
if(!expr){ return ""; }
if(typeof expr.data != "object"){
if(expr.isCol){
return "column(\"" + expr.data + "\")";
}
return "\"" + expr.data + "\"";
}else{
var exprs = [];
for(var i in expr.data){
exprs.push(toExpr(expr.data[i]));
}
var op = expr.op;
if(expr.op == "and"){
op = "logicand";
}
if(expr.op == "or"){
op = "logicor";
}
return op + "(" + exprs.join(",") + ")";
}
};
console.log("expr is: ", expr);
var newExpr = toExpr(expr);
if(newExpr){ newExpr += ";"}
console.log("expr is: ", newExpr);
return {query: newExpr};
},
,上面的函数输出类似..
logicor(logicor(contain(column("1"),"drawal"),contain(column("2"),"drawal"),contain(column("3"),"drawal"),contain(column("4"),"drawal"),contain(column("5"),"drawal"),contain(column("6"),"drawal"),contain(column("7"),"drawal")));
我能够将函数更改为输出sql,如下所示
var toExpr = function(expr) {
if (!expr) {
return "";
}
if ( typeof expr.data != "object") {
if (expr.isCol) {
return cols.item(expr.data);
// return "column(\"" + expr.data + "\")";
}
return "\"" + expr.data + "\"";
} else {
var exprs = [];
for (var i in expr.data) {
exprs.push(toExpr(expr.data[i]));
}
var op = expr.op;
if (op == 'not') {
return "(" + exprs[0].replace(/=/, '<>').replace(/like/, ' not like ') + ")";
}
if (op == 'contain') {
return "(" + exprs[0] + ' like ' + exprs[1].replace(/^"/, '"%').replace(/"$/, '%"') + ")";
}
if (op == 'startWith') {
return "(" + exprs[0] + ' like ' + exprs[1].replace(/^"/, '"%') + ")";
}
if (op == 'endWith') {
return "(" + exprs[0] + ' like ' + exprs[1].replace(/"$/, '"%') + ")";
}
return "(" + exprs.join(" " + op.replace(/equal/, '=') + " ") + ")";
}
};
var newExpr = toExpr(expr);
if (newExpr) {
newExpr += ";";
}
console.log("expr is: ", newExpr);