前端项目实战52-debugger测试

const parseFilters = (filter: any, defaultListOp: any) => {
    const result: any = {}
    console.log(filter,"filter")
    console.log(defaultListOp,"defaultListOp")
    Object.keys(filter).forEach(function (key) {
        debugger
        // key: the name of the object key
        //属性按照@分割
        const splitKey = key.split('@');
        console.log(splitKey,"splitKey")
        //如果长度为2 取出数组的属性值
        const operation = splitKey.length == 2 ? splitKey[1] : defaultListOp;
        console.log(operation,"operation")
        let values;
        //如果包含like这个属性 拉取到当前的值 拿取到对应的属性值
        if (operation.includes('like')) {
            values = filter[key].trim().split(' ');
        } else {
            values = [filter[key]];
        }
        console.log(values,"values")
        values.forEach((value: any) => {
            //进行拼接
            // if operator is intentionally blank, rpc syntax
            let op = operation.includes('like') ? `${operation}.*${value}*` : operation.length == 0 ? `${value}` : `${operation}.${value}`;
            console.log(op,"oplist")
            console.log(result,"result")
            console.log(splitKey,"splitKey")
            if (result[splitKey[0]] === undefined) {
                // first operator for the key, we add it to the dict
                result[splitKey[0]] = op;
            }
            else {
              
                if (!Array.isArray(result[splitKey[0]])) {
                    // second operator, we transform to an array
                    result[splitKey[0]] = [result[splitKey[0]], op]
                } else {
                    // third and subsequent, we add to array
                    result[splitKey[0]].push(op);
                }
            }
        });

    });
    return result;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值