开发管理系统,碰到了需要配置表达式的地方。花了半天的时间把自己写的整理了一下。页面的效果是下图。
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++){
cond_next_child = $("#"+cond_be

本文介绍了在开发管理系统时如何配置和处理表达式。详细讲述了生成表达式的过程,通过回调函数实现多层table的拼接。接着阐述了解析表达式的方法,一层层解析直至无括号,并使用特定数据结构存储解析结果。最后讨论了回显表达式,特别是处理"()"时,通过getDivHtml和createTableHtml方法实现表达式的正确显示。
最低0.47元/天 解锁文章
123

被折叠的 条评论
为什么被折叠?



