combotree下拉框选项,发送ajax请求

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010082526/article/details/88060213

1.下拉框部分

easyui--combotree

html代码

<input type="text" id="style" name="stryle" style="width:100px" class="easyui-combotree" multiple data-options=" valueFiled:' id', textFiled:'text',panelHeight:'auto' ">

js代码

写在$(function(){})里

$.post('' ,{} ,function(data)

{

} ,'json');

如下,漏掉最后的参数type,‘责任单位’下拉框里的内容全是undefined

jQuery中的Ajaxhttps://blog.csdn.net/u010082526/article/details/88055262
jquery对ajax操作进行了封装,

在jquery中$.ajax()方法属于最底层的方法

第二层是load()、$.get()\$.post()方法,

第三层是$.getScript()和$getJSON()方法。

$.get()方法
结构为:$.get()(url,data,callback,type);

url:String类型,表示请求html页面的统一资源定位器地址;
data:Object类型,发送至服务器的key/value数据;
callback:Function类型,请求完成后的回调函数,无论请求成功或失败。
参数说明:其他如上,type表示服务器端返回内容的格式,包括xml,html,json,等

$.post()方法
结构和$.get()方法相同,不过也有区别,就是一些传递数据的规则不同。

后台拼接的json字符串

public string GetStyleList()
        {
            return "[{\"id\":\"all\",\"text\":\"全部\",\"checked\":true,\"children\":[{\"id\":\"0\",\"text\":\"汽修店类\"},{\"id\":\"1\",\"text\":\"餐饮类\"},{\"id\":\"2\",\"text\":\"加油站类\"},{\"id\":\"3\",\"text\":\"工业企业类\"},{\"id\":\"4\",\"text\":\"工地类\"},{\"id\":\"5\",\"text\":\"环境整治类\"}," +
             "{\"id\":\"6\",\"text\":\"裸露地面类\"},{\"id\":\"7\",\"text\":\"锅炉类\"},{\"id\":\"8\",\"text\":\"城市道路类\"},{\"id\":\"9\",\"text\":\"堵车点位类\"},{\"id\":\"10\",\"text\":\"社会停车场类\"},{\"id\":\"11\",\"text\":\"垃圾收集站点类\"},{\"id\":\"12\",\"text\":\"居民楼类\"},{\"id\":\"13\",\"text\":\"汽修店类\"}]}]";           
        }

此处是多选combotree,选中状态是checked:true

如果是单选combobox,选中状态就是selected:true

2.后台获取参数,查询数据

获取到的Unit等参数为null值,因为前台的$.post()默认是异步请求,没有返回结果的情况下,会执行下面的语句LoadData();

此处可参考https://blog.csdn.net/sunnyzyq/article/details/78730894

https://blog.csdn.net/wang48430327/article/details/80898461

jquery的post异步请求https://www.cnblogs.com/sllcom/p/7859323.html

对前台代码进行修改,改成发布同步请求

3.linq查询报错

https://bbs.csdn.net/topics/310130308

尝试写在findall里

或者,把tostring改成  +“”

 最后,先tolist,在转tostring

https://blog.csdn.net/xiaojia_boke/article/details/8786362

此时,是由于获取到的Unit等参数为null报错($.post()的异步请求造成的)

修改如下

注释掉同步请求,仍保留异步请求,加速页面响应 

4.数据表格--datagrid

参考http://www.jeasyui.net/plugins/183.html

    function LoadData() {
        var para = serializeObject($('#form_search').form());
        dg = $('#dg').datagrid({
            url: '@Url.Action("LoadData", "PatrolRecord")',
            fitColumns: true,
            fit: true,
            pageSize: 20,
            pageNum: 1,
            nowrap:false,
            view: nodataview,
            queryParams: para,
            columns: [[
                { field: 'description', title: '事件', align: 'center', width: '30%' },
                { field: 'monitortime', title: '时间', align: 'center' },
                { field: 'status', title: '是否解决', align: 'center' },
                { field: 'style', title: '曝光类型', align: 'center', width: '30%' },
                { field: 'community', title: '所在社区', align: 'center' },
                { field: 'Unit', title: '责任单位', align: 'center' },
            ]],
            pagination: true
        });
    }

猜你喜欢

转载自blog.csdn.net/u010082526/article/details/88060213
今日推荐