我有一个菜单谁用铁-ajax的内容的网页,这个内容是一个html文件谁有聚合物元素的要求,这工作得很好。我遇到的问题是根据所请求的内容来更改纸张工具栏中的图标。它在聚合物0.5中工作得很好,但在聚合物1.0中不起作用。
这里是我的dom -重复在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>这是我的函数来观察突变,我没有做这个功能,所以我不能完全理解这个函数做什么。
attached: function () {
var self = this;
this.mo = new MutationObserver(function (mutations) {
mutations.forEach(function (m) {
for (i = 0; i < m.removedNodes.length; i++) {
self.content = null;
}
for (i = 0; i < m.addedNodes.length; i++) {
self.content = m.addedNodes[i];
}
});
}.bind(this));
this.mo.observe(this.$.content, { childList: true });
}因此,当我调用某些内容时,第一次更改上下文按钮,但其他时候什么也没有发生,我使用
$0.contextualButtons数组如我所预期的那样变化,甚至我也将额外的对象推入数组中,但是dom没有改变。
$0.contextualButtons.push({ icon: 'social:person-addss', action: 'new' })我的数组的声明如下:
contextualButtons: {
type: Array,
value: function () { return []; },
observer: '_contextualButtonsChange'
//reflectToAttribute: true,
//notify: true
}我试图使用观察者,reflectToAttribute和通知,但它不起作用,也许我不能完全理解它是如何工作的。
有人能帮我吗?顺便说一句,对不起我的英语。塔克斯!
发布于 2015-08-17 22:48:07
过了一段时间,我找到了问题的答案,这个问题是你能想象得到的最简单的解决方法,是的,创建了一个新的自定义元素。这是我的元素,以防有人需要这样的东西。
<script>
Polymer({
is: 'my-toolbar-icons',
properties: {
contextualButtons: {
type: Array,
value: function () {
return [];
}
}
},
ready: function(){
//set data just to show an 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 to the 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>
https://stackoverflow.com/questions/31411091
复制相似问题