开发管理系统,碰到了需要配置表达式的地方。花了半天的时间把自己写的整理了一下。页面的效果是下图。
1.生成表达式
页面是有多个table块嵌套而成的。在拼接表达式的时候可以使用回调,具体的方法实现如下:
function doaddCondition(tableId){
var expression = '';
var spanId = $("#"+tableId+" td:first-child").attr("id");
var word = $("#"+spanId+" span[class=\'show-cond-word\']").attr("name");
var symbol = "and";
if(word=='word1'){
symbol = 'and';
}else if(word='word2'){
symbol = "or";
}
var condition_id = $("#"+spanId).next().attr("id");
var condition_lenght = $("#"+condition_id).children().length;
var cond_before_child = $("#"+condition_id+" :first-child").attr("id");
console.log("处理该div下的第一个代码块");
if(checkTable(cond_before_child)){
console.log("这个块是table块");
expression ="("+doaddCondition(cond_before_child)+")";
}else{
console.log("这是个div块");
var select1 = $("#"+cond_before_child+" select[name=\'select1\']").val();
var select2 = $("#"+cond_before_child+" select[name=\'select2\']").val();
var text = $("#"+cond_before_child+" input[name=\'text1\']").val();
if(checkInfo(select1)&&checkInfo(select2)&&checkInfo(text)){
expression =select1+select2+"'"+text+"'";
}else{
return false;
}
}
var cond_next_child = cond_before_child;
for(var i=0;i<condition_lenght-1;i++){