<dom-module id="test-element">
<template>
<template is="dom-repeat" items="[[items]]">
<content></content>
<div>[[item]]</div>
</template>
</template>
<script>
(function () {
Polymer({
is: 'test-element',
properties: {
items: {
type: Array,
value: []
}
},
attached: function () {
console.log('attached');
this.push('items', "1");
this.push('items', "2");
this.push('items', "3");
console.log('items=' + this.items); // The 1st instance of the element displays 'items=1,2,3' the 2nd displays 'items=1,2,3,1,2,3' !!!!
}
});
})();
</script>
</dom-module>
<!DOCTYPE html>
Read the docs on properties and you'll see a statement about using:
value: function() { return []; }
In relation to arrays and objects with the appropriate change to the function.
Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/6a372d9b-fc65-4dd6-9a66-f6020aa39c1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thinking about the mechanics of this, I can now see why it works this way. However, it is still a pretty nasty gotcha and it might be worth looking at that area of the documentation and making this issue a bit more obvious.
Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/08b6ea93-1fde-4d29-8271-71b5cf859343%40googlegroups.com.
There's really no way to do that. Critically, there's no way to fully clone an object.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/efa312f3-1cdc-4775-8efc-b3edec890adc%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/efa312f3-1cdc-4775-8efc-b3edec890adc%40googlegroups.com.
Polymer({
is: 'txt-carousel-view',
properties: {
myOwnList: {
value: function() { return []; } // this is a non-static array, invididual and fresh for every instance
},
mySharedList: {
value: []; // this is a static array, shared with every instance array
}
}
})
1. By default, properties of Polymer objects are shared across all instances of the object (or, to be more precise, all references to the object, since Polymer doesn't create new instances, as in "new Element()"). Basically, all properties are by default static.
2. Every property that is supposed to be individual to the specific reference, in other words, be not static, and changable without messing with any other instance/reference, has to have the field "value: function() { return []; }".
This is a problem with Javascript in general and not specific to Polymer.
Dan.
Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to a topic in the Google Groups "Polymer" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/polymer-dev/pa_Ak2ATRw8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to polymer-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/CABtuYwfLtupeCsgP-NVxoXbHEC2Yqna9%3DyfRuqCXxQRjGKVgXQ%40mail.gmail.com.
You received this message because you are subscribed to a topic in the Google Groups "Polymer" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/polymer-dev/pa_Ak2ATRw8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to polymer-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/69a506c3-3898-4a64-ab17-f974e51bcfd1%40googlegroups.com.
To unsubscribe from this group and all its topics, send an email to polymer-dev...@googlegroups.com.