javascript - How to bind an array of objects in Polymer 1.0? -
i have menu calls iron-ajax content of page, content html file has polymer element requested, works fine. problem have change icons in paper-toolbar depending of content requested. works fine in polymer 0.5, in polymer 1.0 doesn't work.
here dom-repeat put icons in dom
<template is="dom-repeat" items="{{content.contextualbuttons}}" as="button" id="repitebotones"> <paper-icon-button contextual-action="{{button.action}}" icon="{{button.icon}}" on-tap="{{oncontextualbuttontap}}"></paper-icon-button> </template>
this function observer mutations, didn't function, can't understand function does.
attached: function () { var self = this; this.mo = new mutationobserver(function (mutations) { mutations.foreach(function (m) { (i = 0; < m.removednodes.length; i++) { self.content = null; } (i = 0; < m.addednodes.length; i++) { self.content = m.addednodes[i]; } }); }.bind(this)); this.mo.observe(this.$.content, { childlist: true }); }
so, when call content, first time changes contextual buttons, other times nothing happened, checked array using
$0.contextualbuttons
and array changes expected, push objects array, dom not changes
$0.contextualbuttons.push({ icon: 'social:person-addss', action: 'new' })
the declaration of array this:
contextualbuttons: { type: array, value: function () { return []; }, observer: '_contextualbuttonschange' //reflecttoattribute: true, //notify: true }
i tried use observer, reflecttoattribute , notify not works, maybe cant understand how works.
anyone can me? way, sorry english. thaks!
after sometime, found response of question, problem resolved easy way can imagine, yes, creating new custom element. here element in case needs this.
<script> polymer({ is: 'my-toolbar-icons', properties: { contextualbuttons: { type: array, value: function () { return []; } } }, ready: function(){ //set data show icon this.contextualbuttons = [{ icon: 'social:person-add', action: 'new' }, { icon: 'delete', action: 'delete' }, { icon: 'cloud-upload', action: 'update' }, { icon: 'image:camera-alt', action: 'takephoto' }, { icon: 'search', action: 'search' }]; }, setdata: function (newcontextualbuttons) { //set data array (usage) //var item = document.queryselector("#id-of-this-element") //item.setdata(somearrayoficons) this.contextualbuttons = newcontextualbuttons; }, oncontextualbuttontap: function (event) { var item = this.$.buttonsrepeat.itemforelement(event.target); this.fire('customize-listener', item.action); } }); </script>
Comments
Post a Comment