Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
102 views
in Technique[技术] by (71.8m points)

javascript - Concatenating JSON rules to filter data

I'm working with an API that has a large data set that filters products by type, category, etc.

In each JSON object, for each item in the array, there is a key called code:`` followed by a string (example: "FRULE137980". Each sub category also have arrays with this key and rule. In the sub category, in addition to the code:key, there is aproductCount```

This is what the URL looks like when you filter down your product selection.

"https://www.somewebsite.com/prodouct/product-category--CAT33-c?sellingAidsFilter=SRULE4663&ruleFilter=FRULE137980%2CFRULE1933147%2CFRULE1914521%2CFRULE1914663" This returns the product count in each applied filter.

I am working with a 6 step form and have to filter down the productCount in each step. How do I concatenate the rules in each step to return the correct productCount? I've only been able to successfully do this in the second step using this method:

    const changeProductCount = () => {
        let sum = 0;
        changeProductCount.forEach(function () {
            let calculation =
                filters.sellingAidsFilter - content.content.facetFilters[0];
            sum += calculation;
        });
        return sum;
    };

However, this seems redudant to keep have to do a calculation in each step. Sorry for the n00b question, but thanks in advance.

question from:https://stackoverflow.com/questions/65951115/concatenating-json-rules-to-filter-data

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...