zoukankan      html  css  js  c++  java
  • 一个 函数 用来转化esSearch 的range 条件

     var filterData =  [
                        {    "component":"filter-criteria",
                            "index":"b04ec5bb5237494da067fed200d4d4a8",
                            "data":{"size":10,
                                "field":"Speed",
                                "fieldType":"数字",
                                "selSimbol":"<",
                                "filter":{
                                    "from":"2017-11-13T05:50:22.121Z",
                                    "to":"2017-11-13T05:50:22.121Z",
                                    "start":0,
                                    "end":20,
                                    "timeValue":"",
                                    "simbolValue":"50"
                                    }
                            }
                        },
                        {"component":"filter-criteria",
                        "index":"4ad0d99143b44151b6e8d76d1e85bb9e",
                        "data":{
                                "size":"101",
                                "field":"Time",
                                "fieldType":"时间",
                                "selSimbol":">",
                                "filter":{
                                    "from":"2017-11-13T05:50:27.780Z",
                                    "to":"2017-11-13T05:50:27.780Z",
                                    "start":0,
                                    "end":20,
                                    "timeValue":
                                    "2017-11-13T05:50:27.780Z",
                                    "simbolValue":"100"
                                    }
                              }
                        }
                                ];
      
      console.log(JSON.parse(JSON.stringify(filterData)));
      var ffdd = JSON.parse(JSON.stringify(filterData));
    
      function parseFilter(arr){
          
          var rangeFilter = [], range = [];
            for(var kk=0;kk<arr.length;kk++){
                console.log(arr[kk].data.fieldType)
                    if(arr[kk].data.fieldType.toString()=="数字"){
                        //alert(2)
                        switch(arr[kk].data.selSimbol){
                            case "<":
                                range[arr[kk].data.field] = {
                                    "lt":arr[kk].data.filter.simbolValue
                                }
                                console.log('<的range')
                                console.log(range)
                            break;
                            case ">":
                                range[arr[kk].data.field] = {
                                    "gt":arr[kk].data.filter.simbolValue
                                }
                                
                                break;
                        }
                        
                    }else if(arr[kk].data.fieldType.toString()=="时间"){
                        //alert(1)
                        switch(arr[kk].data.selSimbol){
                            case "<":
                                range[arr[kk].data.field] = {
                                    "lt":arr[kk].data.filter.timeValue
                                }
                                console.log('<的range')
                                console.log(range)
                            break;
                            case ">":
                                range[arr[kk].data.field] = {
                                    "gt":arr[kk].data.filter.timeValue
                                }
                                
                                break;
                        }
                    }
                    var bb={};
                    for(var key in range ){
                        if(arr[kk].data.field == key){
                            bb[key] = range[key];
                            rangeFilter.push({
                                "range":bb
                            })
                        }
                    }
                    
                }
                console.log('range54646546')
                console.log(range)
                //parseRange(range);
                //console.log(parseRange(range));
                console.log('华丽的分割线')
                
    
    
                
                
                console.log('*************')
                console.log('sssss')
                var am =  JSON.stringify(rangeFilter);
                var amt = am.replace("[",'{').replace("]","}")
                
                console.log(amt)
                
    
                console.log('sssss')
                console.log('*************')
                return rangeFilter;
            }
        
      function parseRange(data){
         var a={},b={},index=0;
        for (var key in data){
            b[key] = data[key];
            a["range"] = {};
            if(a["range"].hasOwnProperty(key)){
                return;
            }else{
                a["range"] = b;
            }
        }
    
        return a;
      }
    
      console.log(parseFilter(ffdd))
  • 相关阅读:
    开源WebGIS实施方案(五):基于SLD实现图层符号化及其应用
    开源WebGIS实施方案(四):GeoServer发布PostGIS数据
    开源WebGIS实施方案(三):Shapefile数据导入到PostGIS
    jdbcType与javaType的对应关系
    关于fastjson的一个坑:输出json时,bean对象属性首字母默认被小写
    TortoiseSVN本地版本控制管理
    ArcGIS“一个或多个ActiveX控件无法显示...”问题的解决方案
    JavaWeb学习系列——第一个JavaWeb程序
    ArcGIS提取影像边界
    调皮的MySQL服务 请你不要再躲猫猫
  • 原文地址:https://www.cnblogs.com/vali/p/7827343.html
Copyright © 2011-2022 走看看