If I want to bind the attributes of two polymer elements together, I can use the data binding in the template and do the following:
<polymer-element name="td-model" attributes="items">
<script>
Polymer('td-model', {
ready: function() {
this.items = [1, 2, 3];
}
});
</script>
</polymer-element>
<polymer-element name="my-app">
<template>
<td-model items="{{list}}"></td-model>
<polymer-localstorage name="myapplist" value="{{list}}"></polymer-localstorage>
</template>
<script>
Polymer('my-app', {
ready: function() {
this.list = this.list || [];
}
});
</script>
</polymer-element>
From http://www.polymer-project.org/articles/communication.html#binding
However, if I create an element (let it be called) <my-childelement>dynamically using document.createElement()inside another element <my-parentelement>, then how can I synchronize the changes made to the my-childelement attribute with the my-parent element?
, , , , , / , .
Node.bind() , , , .
, - :
<polymer-element name="my-parentelement" attributes="shape">
<script>
Polymer('my-parentelement', {
shape: square,
ready: function() {
var child = document.createElement('my-childelement');
this.bind('shape', new PathObserver(child, 'shape');
child.shape = 'triangle';
this.shape == child.shape;
}
});
</script>
</polymer-element>