js代码

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Stubborn_Cow/article/details/81301932
var userList = (function(){
    // 表单
    var form=layui.form;
    // 日期
    var laydate=layui.laydate;
    // 表格
    var table=layui.table;
    // 部门树选中项
    var selectedTreeId;

    var method={
        initForm:function(){
            //执行一个laydate实例
            laydate.render({
                elem: '#sdate'
                ,zIndex: 99999999
                ,showBottom: false
            });
            //执行一个laydate实例
            laydate.render({
                elem: '#sdate2'
                ,zIndex: 99999999
                ,showBottom: false
            });
        },
        initSelect:function(){
            // 初始化下拉 
            page.dataFactory.call(api.name.userType.get,"",function success(result){
                page.initSelect("#utype",result.data,form);
            });
        },
        initTable:function(){
            var url =page.dataFactory.getTableUrl(api.name.users.get);
            // 初始化table
            table.render({
                elem: '#userTable'
                ,id: 'optUserTable'
                ,url: url
                ,page: {
                    layout: curPage.table.layout
                }
                ,limit:curPage.table.limit
                ,cols: [[
                    {type:'checkbox'}
                    ,{field:'id',}
                    ,{field:'username', width:80, title: '用户名'}
                    ,{field:'sex', width:80, title: '性别'}
                    ,{field:'city', width:80, title: '城市'}
                    ,{field:'sign', title: '签名', minWidth: 150}
                    ,{field:'experience', width:80, title: '积分'}
                    ,{field:'score', width:80, title: '评分'}
                    ,{field:'classify', width:80, title: '职业'}
                    ,{field:'wealth', width:135, title: '财富'}
                ]]
                ,height:curPage.table.Height
                ,done:function(res,curr,count) {
                    // 隐藏列
                    $("[data-field='id']").css('display','none');
                }
            });

        },
        zTreeOnClick:function(event, treeId, treeNode){
            selectedTreeId = treeNode.id;
            method.reloadTableData();
        },
        initTreeData:function(){
            // 添加tree数据
            page.ajax.call.(api.name.treeDepartment, "", function success(data) {
                selectedTreeId = "";
                // 初始化树结构
                curPage.obj.treeSetting.callback.onClick=method.zTreeOnClick ;
                $.fn.zTree.init($("#treeDemo"), curPage.obj.treeSetting, data);
            });
        },
        reloadTableData:function (){
            // 查询条件
            var searchCond =$("#searchForm").serializeFormObject();
            // 选中部门
            searchCond.departmentId = selectedTreeId;
            // 重载table
            page.reloadTable(table,"optUserTable",searchCond);
        },
    };

    var bind={
        event:{
            search :function(){
                $("#search").on('click', function(){
                    method.reloadTableData();
                });
            },
            add : function(){
                $('#add').on('click', function(){
                    page.showForm({
                        url:"user/userForm.html",
                        type:"add",
                        submit:function(iframeWin,index){
                            if(iframeWin.userForm.save()){
                                page.closeForm(index);
                                method.reloadTableData();
                            }
                        }
                    })
                });
            },
            update:function(){
                $('#update').on('click', function() {
                    // 获取选中数据
                    var data = page.getTableRowByChoose(table, "optUserTable");
                    // 选中判断
                    if(page.checkUpdateByChoose(data)) {
                        page.showForm({
                            url: "user/userForm.html",
                            type: "update",
                            param: {
                                id: data[0].id
                            },
                            submit: function (iframeWin, index) {
                                if (iframeWin.userForm.save()) {
                                    page.closeForm(index);
                                    method.reloadTableData();
                                }
                            }
                        });
                    }
                });
            },
            delete : function(){
                $('#delete').on('click', function(){
                    // 获取选中数据
                    var data = page.getTableRowByChoose(table,"optUserTable");
                    // 选中判断
                    if(page.checkDeleteByChoose(data)) {
                        // 执行删除
                        page.showConfirm("确认删除?", function () {
                            method.reloadTableData();
                        })
                    }
                });
            },
            detail :function(){
                $(document).on("dblclick",".layui-table-view tbody tr", function () {
                    var rowObj = page.getTableRowByDblClick(this);
                    page.showForm({
                        url:"user/userForm.html",
                        type:"detail",
                        param:{
                            id:rowObj.id
                        }
                    })
                });
            }
        }
    };

    var init =function(){
        // 初始化表单
        method.initForm();
        // 初始化树数据
        method.initTreeData();
        //初始化下拉
        method.initSelect();
        //初始化table
        method.initTable();
        // 绑定事件
        bind.event.add();
        bind.event.update();
        bind.event.delete();
        bind.event.detail();
        bind.event.search();
    };

    init();
})();

 

展开阅读全文

一段JS代码

01-25

// A simple helper that allows you to bind new functions to thern// prototype of an objectrnFunction.prototype.method = function(name, func) rnthis.prototype[name] = func;rnreturn this;rn;rn// A (rather complex) function that allows you to gracefully inheritrn// functions from other objects and be able to still call the 'parent'rn// object's functionrnFunction.method('inherits', function(parent) rn// Keep track of how many parent-levels deep we arernvar depth = 0;rn// Inherit the parent's methodsrnvar proto = this.prototype = new parent();rn// Create a new 'priveledged' function called 'uber', that when calledrn// executes any function that has been written over in the inheritancernthis.method('uber', function uber(name) rnvar func; // The function to be executernvar ret; // The return value of the functionrnvar v = parent.prototype; // The parent's prototypern// If we're already within another 'uber' functionrnif (depth) rn// Go the necessary depth to find the orignal prototypernfor ( var i = d; i > 0; i += 1 ) rnv = v.constructor.prototype;rnrn// and get the function from that prototypernfunc = v[name];rnCHAPTER 3 n CREATING REUSABLE CODE 41rn// Otherwise, this is the first 'uber' callrn else rn// Get the function to execute from the prototypernfunc = proto[name];rn// If the function was a part of this prototypernif ( func == this[name] ) rn// Go to the parent's prototype insteadrnfunc = v[name];rnrnrn// Keep track of how 'deep' we are in the inheritance stackrndepth += 1;rn// Call the function to execute with all the arguments but the firstrn// (which holds the name of the function that we're executing)rnret = func.apply(this, Array.prototype.slice.apply(arguments, [1]));rn// Reset the stack depthrndepth -= 1;rn// Return the return value of the execute functionrnreturn ret;rn);rnreturn this;rn);rn// A function for inheriting only a couple functions from a parent object,rn// not every function using new parent()rnFunction.method('swiss', function(parent) rn// Go through all of the methods to inheritrnfor (var i = 1; i < arguments.length; i += 1) rn// The name of the method to importrnvar name = arguments[i];rn// Import the method into this object's prototypernthis.prototype[name] = parent.prototype[name];rnrnreturn this;rn);rnrnrn求// A (rather complex) function that allows you to gracefully inheritrn// functions from other objects and be able to still call the 'parent'rn// object's function 以后代码的详细解释,特别是rnfor ( var i = d; i > 0; i += 1 ) rnv = v.constructor.prototype;rnrn这是什么意思,无限循环?rn还有ret = func.apply(this, Array.prototype.slice.apply(arguments, [1]));其中Array.prototype.slice.apply(arguments, [1])这是什么意思 论坛

js代码不执行

10-20

我是刚刚开始学java web的大学生,最近老师布置了任务就是用spring mvc实现mysql数据库的增删改查,现在出现了一个很奇怪的问题,求各位大神给点意见,rn就是比如我修改或新增用户时,[color=#FF0000]点击esayui对话框中的保存没有反应,就是连报错都没有。[/color]rn相关代码如下,下面是body中修改用户的按钮和easyui的对话框:rn rn 新建用户 修改用户信息 删除用户 查看rn rn rn rn rn rn 用户序号:rn rn rn rn 用户编号:rn rn rn rn 用户姓名:rn rn rn rn 年龄:rn rn rn rn 性别:rn rn rn rn 生日:rn rn rn rn rn rn rn rn 保存 rn 关闭rn rn以修改信息为例,下面是相关的js函数:rnfunction [color=#FF0000]modifyRecord()[/color] rn var row = $('#infoTable').datagrid('getSelected');rn if (row) rn $('#editDlg').dialog('open').dialog('setTitle', '修改用户信息');rn //不可修改项rn $('#userId').attr("disabled", "disabled");rn $('#pkId').attr("disabled", "disabled");rn $('#userInfoEditForm').form('load', row);rn url = '<%=request.getContextPath()%>/manager/userController/modifyUser.do';rn else rn $.messager.alert('提醒', '请选择需要修改的行', 'warning');rn rn rnfunction [color=#FF0000]saveInfo[/color]()rn [color=#FF9900]$('#userInfoEditForm').form('submit'[/color], rn url : url,rn onSubmit : function() rn return $(this).form('validate');rn ,rn success : function(result) rn var result = eval('(' + result + ')');rn if (result.errorMsg) rn $.messager.show(rn title : 'Error',rn msg : result.errorMsgrn );rn else rn $.messager.alert('info',result.success,'info',function()rn $('#editDlg').dialog('close');rn $('#infoTable').datagrid('reload');rn );rn rn ,error:function(XMLHttpRequest, textStatus, errorThrown)rn $.messager.alert('error','严重错误,联系管理员');rn rn );rn rn点击修改用户信息之后,把弹出的对话框填好,点击保存,就是没有任何反应,没有跳转到url指向的controller中的方法,也没有报错;加了debugger发现是SavaInfo中[color=#FF9900]$('#userInfoEditForm').form('submit'[/color]之后的代买没有执行,非常奇怪,跪求各位了! 论坛

没有更多推荐了,返回首页