js 中多个函数的 放到一个对象中形成一个集合提供工具服务类的功能

        inOutService.getRoleType();
        inOutService.initSystemData_UB();
        inOutService.initSystemData_depot();
        inOutService.initSystemData_account();
        inOutService.initSupplier(); //供应商
        inOutService.initSalesman(); //销售人员
        inOutService.initOutItemList(); //初始化支出项目
        inOutService.initMProperty(); //初始化商品属性

类似上边的写法在前端js 中,跟后端的语法写法怎么一样了

乍一看,不会像c#中webapi项目某个第三方框架的那种,写个宏,前端可 直接调用后端的方法吧 . 看看在哪定义的,原来是 

js定义一个对象函数都放进去,就可以这么调用了.   js 中大括号{} 括起来的是对象, [] 中括号 是数组.

var inOutService = {
        getRoleType: function () {
            $.ajax({
                type:"get",
                url: "/user/getRoleTypeByUserId",
                async: false,
                success: function (res) {
                    if (res && res.code === 200) {
                        roleType = res.data.roleType;
                    }
                    else {
                        roleType = null;
                    }
                }
            });
        },
        //初始化系统基础信息
        initSystemData_UB: function () {
            $.ajax({
                type:"get",
                url: "/userBusiness/getBasicData",
                data: ({
                    KeyId:kid,
                    Type:"UserDepot"
                }),
                //设置为同步
                async:false,
                dataType: "json",
                success: function (res) {
                    if (res && res.code === 200) {
                        userBusinessList = res.data.userBusinessList;
                        if(userBusinessList !=null) {
                            if(userBusinessList.length>0) {
                                //用户对应的仓库列表 [1][2][3]...
                                userdepot =userBusinessList[0].value;
                            }
                        }
                    }
                    else {
                        userBusinessList = null;
                    }
                }
            });
        },
        //初始化系统仓库信息
        initSystemData_depot: function () {
            var config = getSystemConfig();
            var depotList = getSystemDepot();
            if(depotList !=null) {
                for(var i = 0 ;i < depotList.length;i++) {
                    var depot = depotList[i];
                    if(config && config.depotFlag == "1") {
                        if(userdepot!=null) {
                            if(userdepot.indexOf("["+depot.id+"]")!=-1) {
                                if(depot.isDefault){
                                    defDepotId =  depot.id;
                                }
                                depotString = depotString + depot.id + ",";
                            }
                        }
                    } else {
                        if(depot.isDefault){
                            defDepotId =  depot.id;
                        }
                    }
                }
                depotString = depotString.substring(0, depotString.length-1);
            }
        },
原文地址:https://www.cnblogs.com/zuochanzi/p/13947197.html