• easyui datagrid 遇到的坑 cannot read property ·· pageNum bug and so on


    1 本人刚刚接到一个bug,就是初始化时若设置了datagrid到指定页数,点击下一页显示不对,4 --> ‘4’+1=41的字符串形式,再点击超出页码范围直接到最后一页;

    原因:因为 pageNumber接收的是整数型的数据,而你遇到这种bug说明你传入的非整型的数据,需要利用parseInt进行转化一下,就不会再出现这样的错误了;

    function queryTable(params) {
            $('#tt').datagrid({
                 $(".queryTable").width()+60,
                height:($(window).height()-240),
                queryParams: params||{},
                pageNumber:parseInt(prepage)||'',
                pageSize:parseInt(prerows)||'',
                singleSelect: true,
                loadMsg: "Loading, please wait ...",
                pageList: [15,25,35,45,65,100],
                idField:'id',
                url:'/CarlcareManager/posts/findPostLists',
                method:'get',
                columns:[[
                    {field:'post_language',title:'Language','8%',align:'center'},
                    {field:'post_type',title:'Type',align:'center','8%',formatter:function(val,obj,idx){
                        var rtn='';
                        if(val!=0&&val==''){
                            rtn='';
                        }else{
                            switch(val){
                                case 1:
                                    rtn='Official';
                                    break;
                                case 2:
                                    rtn='Skill';
                                    break;
                                case 3:
                                    rtn='Problem';
                                    break;
                                case 4:
                                    rtn='Entertainment';
                                    break;
                                case 9:
                                    rtn='Others';
                                    break;
                            }
                        }
                        return rtn;
                    }},
                    {field:'publish_time',title:'Publishing time','8%',align:'center',formatter:function(val,obj,idx){
                        return dateFormat(parseInt(val));
                    }},
                    {field:'username',title:'Owner','8%',align:'center'},
                    {field:'post_title',title:'Title','18%',align:'center'},
                    {field:'view_count',title:'Views','6%',align:'center'},
                    {field:'reply_count',title:'Comments','6%',align:'center'},
                    {field:'collect_count',title:'Favorites','6%',align:'center','10%'},
                    {field:'comment',title:'Marks','10%',align:'center'},
                    {field:'post_status',title:'Status','6%',align:'center',formatter:function(val,obj,idx){
                        var rtn='';
                        if(val==1){
                            rtn='Published';
                        }else{
                            rtn='Delete';
                        }
                        return rtn;
                    }},
                    {field:'view_status',title:'Operation','10%',align:'center',formatter:function(value,obj,index){
                        var html='';
                        if(value==1){
    //            html="<a class='viewed' type='button' name='replyStatus' onclick='postDetail(obj.id,obj.post_status)' href='../customer/postDetailPage?postId="+obj.id+"&postStatus="+obj.post_status+"' value='View'>View</a>";
                            html="<a class='alink viewed' type='button' name='replyStatus' onclick='postDetail("+obj.id+","+obj.post_status+")' value='View'>View</a>";
    
                        }else{
    //            html="<a class='unviewed' type='button' name='replyStatus'  onclick='postDetail(obj.id,obj.post_status)' href='../customer/postDetailPage?postId="+obj.id+"&postStatus="+obj.post_status+"' value='UnView'>UnView</a>";
                            html="<a class='alink unviewed' type='button' name='replyStatus'  onclick='postDetail("+obj.id+","+obj.post_status+")' value='UnView'>UnView</a>";
    
                        }
                        return html;
                    }}
    
                ]],
                onLoadSuccess:function(data){
                },
                onLoadError:function(){
                }
            });
            $('#tt').datagrid("clearSelections");
        }

     2 datagrid表格初始化时总是会报错 cannot read property ‘width/height··’

    我碰到的发生这种错误有两种原因(easyui datagrid内部有不能识别的数据)

    a - field单词拼写错误

    b - queryTable请求地址拿回来的数据格式不对,比如下面,拿回的数据若不是rows会报类似错误;

     

     3 今天在使用jquery easyui时遇到一个问题,easyui的datagrid无法加载。可能原因是field里面存在空格;

  • 相关阅读:
    【LeetCode】两个有序数组合成一个有序数组(NEW)
    swiftmonkey 源码剖析及二次开发思路
    CentOS7 + Python3 + Django(rest_framework) + MySQL + nginx + uwsgi 部署 API 开发环境, 记坑篇
    Vue 5小时学习小教程
    【LeetCode】两数相加
    (vue.js)vue中引用了别的组件 ,如何使this指向Vue对象
    Monkey for Mac 环境配置
    [Vue] 初识Vue-常用指令
    利用Tkinter做的自动生成JSONSchema的小工具
    Linux下如何删除非空目录
  • 原文地址:https://www.cnblogs.com/xhliang/p/8193744.html
Copyright © 2020-2023  润新知