前端项目实战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;
}

posted @ 2022-10-22 17:03  前端导师歌谣  阅读(45)  评论(0)    收藏  举报