Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear an array in Polymer?

The polymer documentation says to always use the polymer array mutation functions when manipulating arrays. I do not see a function to clear an array. I see pop, push, shift, unshift and splice. For now i using this method:

<script>
    Polymer({
        is: "wc-example",
        properties: {
            data: { type: Array, value: function () { return [1, 2, 3]; } }
        },
        ready: function () {
            this.data = [];
        }
    });
</script>

This works but it doesn't seem right because i'm not using the array mutation functions. Does anyone know the correct solution?

Thank you!

like image 521
CLaff Avatar asked Dec 25 '22 07:12

CLaff


1 Answers

This perfectly ok. You are assigning a new instance to the property and this will be tracked by Polymer. Only manipulations on the same instance need to be done using the Polymer API. Note that you could use splice to clear an array.

this.splice("data", 0, this.data.length)
like image 92
Maria Avatar answered Jan 07 '23 20:01

Maria