zoukankan      html  css  js  c++  java
  • 数据回调处理。导出json/js文件,省市区三级联动拉取

    搜了好久都没有看见想要的数据格式只能自己拉取已了,不来很抗拒回调来处理函数,自认回调用的是一知半解的状态,太难了。。。

    线来截图

    处理前 :

    处理中:

    处理后下载:

    处理结果:

     代码部分:

            window.onload=function(){
                function filterAffixTags(routes) {
                let tags = []
                routes.forEach((route,index) => {
                    const tagPath = {}
                    tagPath.value=route.label
                    tagPath.label=route.label
                    tags.push(tagPath)
                    if (route.children) {
                    const tempTags = filterAffixTags(route.children)
                    tags[index].children=tempTags
                    }
                })
                return tags
                }
                let aa=filterAffixTags(cityData)
                saveJSON(aa,'cityLable.js')
                console.log(aa,'---------处理后 ,城市名赋值为value')
            }
            function saveJSON(data, filename){
                    if(!data) {
                        alert('保存的数据为空');
                        return;
                    }
                    if(!filename) 
                        filename = 'json.json'
                    if(typeof data === 'object'){
                        data = JSON.stringify(data, undefined, 4)
                     }
                    var blob = new Blob([data], {type: 'text/json'}),
                    e = document.createEvent('MouseEvents'),
                    a = document.createElement('a')
                    a.download = filename
                    a.href = window.URL.createObjectURL(blob)
                    a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
                    e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
                    a.dispatchEvent(e)
            }

     数据处理前:

    https://blog-static.cnblogs.com/files/enhengenhengNymph/cityData.js

    数据处理后:

    https://blog-static.cnblogs.com/files/enhengenhengNymph/cityLable.js

  • 相关阅读:
    Java设计模式之装饰模式
    学习Emacs系列教程(二):导航
    Android ProgressDialog 延时消失
    java设计模式装饰模式
    Java 字节流和字符流的相互转换
    emacs配置颜色主题
    Android ProgressDialog的使用
    个人管理 时间管理GTD流程图
    jQuery - 列表控件推荐
    WPF - 模板查看工具:Show Me The Template及如何查看第三方主题
  • 原文地址:https://www.cnblogs.com/enhengenhengNymph/p/14600381.html
Copyright © 2011-2022 走看看