上面是组件的样式 有两个查询功能
首先看前台代码的实现
<div id="tb" style="padding:2px 5px;">
<form id="LogParForm">
<a οnclick="$('#LogGrid').datagrid('reload');" class="easyui-linkbutton c1" data-options="iconCls:'icon-reload',plain:true,">重载</a>
<a οnclick="LogGridLoad({par:null});$('#LogParForm').form('clear')" class="easyui-linkbutton c1" data-options="iconCls:'icon-reset',plain:true,">清空条件</a>
<label> 模块 :</label>
<input id="LogMode">
<label> IP :</label>
<input id="LogIp" placeholder="按IP筛选">
</form>
</div>
js代码
<script type="text/javascript">
$(document).ready(function() {
$('#LogMode').combobox({
url:'{:U("menu/getMode")}',
valueField:'id',
textField:'name',
onSelect:function(re){
//给重新加载数据组装查询条件 这里用的是三维数组 array("后台接受参数名称"=>array("字段"=>array("查询条件","查询值")))
LogGridLoad({par:{mode:{c:'eq',val:re.code}}})
}
});
$('#LogIp').change(function(e) {
var ip = $(this).val();
LogGridLoad({par:{ip:{c:'like',val:'%'+ip+'%'}}})
});
LogGridLoad = function(arr){
$('#LogGrid').datagrid('load',arr);
}
});
</script>
看后台实现代码片段
$post_data = $this->_post();<span style="white-space:pre"> </span>//接受post参数<span style="white-space:pre"> </span>
$map = null;
if(!empty($post_data['par'])){
<span style="white-space:pre"> </span>//将查询条件组装
<span style="white-space:pre"> </span>foreach ($post_data['par'] as $k=>$v){
<span style="white-space:pre"> </span>$map[''.$k.'']=array(''.$v['c'].'',$v['val']);
<span style="white-space:pre"> </span>}
}
$list = $m->where($map)->cache(true)
<span style="white-space:pre"> </span>->order($post_data['sort'].' '.$post_data['order'])
<span style="white-space:pre"> </span>->page($post_data['page'].','.$post_data['rows'])->select();
ok 到这里查询功能就实现了,添加查询的字段很方便,只要定义数组就可以了,此查询方式展示不支持多条件查询,后期会更新
如果有什么问题可以问我哦 QQ296404875