一个 函数 用来转化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))
复制代码

 

posted @   Terre  阅读(1848)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
阅读排行:
· Sdcb Chats 技术博客:数据库 ID 选型的曲折之路 - 从 Guid 到自增 ID,再到
· .NET Core GC压缩(compact_phase)底层原理浅谈
· Winform-耗时操作导致界面渲染滞后
· Phi小模型开发教程:C#使用本地模型Phi视觉模型分析图像,实现图片分类、搜索等功能
· 语音处理 开源项目 EchoSharp

风光无限好

点击右上角即可分享
微信分享提示