stef
428
9
Vue

Compare and filter json params on click

Posted 6 months ago by stef

Hello, i am new to vue and i have a question.

How can i compare json params and filter them?

When i click on ID 1, then compare ID with rules and if it is true, filter them, otherwise not.

Here is my code:

VueTest

            <h3>{{product.title}}</h3>
            <button class="btn btn-md btn-primary" @click="removeChild(product)">{{product.rules}}</button>
        </div>


    </div>
</div>
new Vue({

    el:"#app",
    name:"App",
    data:{

        products:[
            {"id": 1, "title": "iPad 4 Mini", "price": 500.01, "inventory": 2, "rules":0},
            {"id": 2, "title": "H&M T-Shirt White", "price": 10.99, "inventory": 10,"rules":1},
            {"id": 3, "title": "Charli XCX - Sucker CD", "price": 19.99, "inventory": 5,"rules":0}
        ]

    },
    methods:{

        removeChild: function (product){
            return this.products = this.products.filter(product => product.id === product.rules);
        }

    }

});

Thx for your help :-)

Please sign in or create an account to participate in this conversation.