Link to home
Start Free TrialLog in
Avatar of t3chguy
t3chguyFlag for United States of America

asked on

Group like values in Javascript

I have a script in which I select a primary location from a drop down box.  On change, an ajax called is made to a PHP file which returns an array of items, products, and the inventory level for that each of those.

The javascript array looks like this:


Open in new window

What I'm hoping to do is loop through each of those results and have it complete the following logic:

If the product_id equals 0, group by the item_id, otherwise, group by the product_id.

This grouping should essentially tell me the total inventory level for each item or product that was returned.

I then have an HTML page which I will be passing these values back to.

Say my page has an html table that looks like this:

Product 1
Product 1

Item 180

Item 192
Item 192

If the inventory grouping returned in javascript equals the total number of products ids on the page, it would return a "OK" value to the html page.  If There are more items on the page than what is available in inventory, it would return a "NO" value to the html page.

I guess the first part of this would be getting the items to group so I know exactly what is in inventory for each product/item.

I'm sure I'll need to pass a "total_requested" value back with the initial array to compare the values to see if we have enough in stock for the warehouse selected.
Avatar of hielo
Flag of Wallis and Futuna image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial