• js对象转超链接


    search对象转为超链接

    var search = {
        staff_name:{"value":"jack","operator":"like","type":"both"},
        enable_flag:{"value":"1","operator":"=","type":""},
        month:{"value":"","operator":"=","type":""},
    }
    
    
    
    var a = Object.keys(search).reduce((t, i) => {
        return t + Object.keys(search[i]).map(j => encodeURI(`search[${i}][${j}]=${search[i][j]}`)).join('&')
    }, '')
    
    console.log(a)

    完整写法:

    /**
     * 拼接搜索参数下载文件
     * @param {object} params 
     * search: {
     *      staff_name:{"value":"","operator":"like","type":"both"},
     *      enable_flag:{"value":"1","operator":"=","type":""},
     *      month:{"value":"","operator":"=","type":""}
     *  },
     * params {
     *  limit:1,
     *  search:search
     * }
     * 
     * 
     * @param {func} callback 
     */
    export function openLink(baseHref,params) {
        let serachStr = ""
        if(params.hasOwnProperty("search")){
            let search = params.search;
            serachStr = Object.keys(search).reduce((t, i) => {
                return t + Object.keys(search[i]).map(j => encodeURI(`search[${i}][${j}]=${search[i][j]}`)).join('&')
            }, '')
            delete(params.search)
        }
        let simpleQuery = [];
        for (let key in params) {
            if (params.hasOwnProperty(key)) {
                console.log(key)
                let val = params[key];
                // if (val instanceof String || val instanceof Number || val instanceof Boolean){
                    simpleQuery.push(key+`=`+val)
                // }
            }
        }
        let simpleQueryStr = simpleQuery.join("&")
        if (serachStr==""){
            window.open(base_url + baseHref + "?"+simpleQueryStr,"_blank")
        }else{
            window.open(base_url + baseHref + "?" + simpleQueryStr + "&" + serachStr, "_blank")
        }
    }
  • 相关阅读:
    Exercise 1.1 Output a name and address
    常用vi编辑器命令行
    每天进步一点点:linux命令---mkdir,mv
    Tomcat的角色配置--Tomcat的后台管理
    centos下修改mysql root密码
    eclipse 比较实用的快捷键
    centos下/etc/sysconfig/下找不到iptables文件
    eclipse 常用设置(二) 优化相关的设置 提速和解决卡顿
    import javax.servlet 出错
    Java 文件下载
  • 原文地址:https://www.cnblogs.com/xuweiqiang/p/12298578.html
Copyright © 2020-2023  润新知