0

MainComponentController

handleClickAddToCartEvent: function(component, event, helper) {
            let product = event.getParam("product");
            let productCart = component.get("v.productCart");
            if (productCart==null){
                productCart =new Map();
            }
            if(productCart.has(product.PricebookEntries[0].Id)){
                productCart.set(product.PricebookEntries[0].Id,(productCart.get(productCart)+1));
                console.log('productCart.has():'+product.PricebookEntries[0].Id +'|'+ productCart.get(product.PricebookEntries[0].Id));
            }
            else{
                productCart.set(product.PricebookEntries[0].Id,1);
            }
            component.set("v.productCart",productCart);
        },

This page has an error. You might just need to refresh it. Action failed: c:MainComponent$controller$handleClickAddToCartEvent [productCart.has is not a function] Failing descriptor: {c:MainComponent$controller$handleClickAddToCartEvent}

1 Answer 1

0

I just wrote <aura:attribute name="productCart" type="List" /> instead of <aura:attribute name="productCart" type="Map" />. Problem in type I should have used type="Map".

1
  • Just in case the comment I made on my edit didn't reach you, things that look like HTML need to be formatted as code (part of a code block, or inline code) for it to be rendered. This (not rendering html, or things that look like it) is a security measure that the stackexchange network takes to protect people from things like XSS, click-jacking, malicious embeds, etc...
    – Derek F
    Commented Mar 30, 2020 at 15:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .