zoukankan      html  css  js  c++  java
  • 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);
                }
            },
  • 相关阅读:
    Jenkins操作学习 --邮箱配置及测试结果构建
    Jenkins操作学习 --初始化安装
    Jenkins操作学习 -- 配置及使用
    Jenkins登录后空白页
    Linux-(kill,wc,killall,ln,cal,date)
    Linux-(tar,gzip,df,du)
    Linux-(chgrp,chown,chmod)
    Linux-文件和目录属性
    Linux-(which,whereis,locate,find)
    Linux-(touch,cat,nl,more|less,head|tail)
  • 原文地址:https://www.cnblogs.com/zuochanzi/p/13947197.html
Copyright © 2011-2022 走看看