我刚刚开始学习聚合物.这是我的聚合物元素的通用版本:
<polymer-element name="my-element">
<template>
<style>
:host {
position:absolute;
width: 200px;
height: 100px;
background-color: green;
}
</style>
<p>my element</p>
<content id="first-in"></content>
<content id="second-in"></content>
</template>
<script>
Polymer('my-element', {
domReady: function() {
alert(this.children[0].getAttribute('title'));
//this returns the value I want to observe
}
});
</script>
<polymer-element>
Run Code Online (Sandbox Code Playgroud)
内容标记都填充了另一个自定义元素(再次略微简化):
<polymer-element name="in-element" attributes="title">
<template>
<style>
...
</style>
<p>{{title}}</p>
</template>
<script>
Polymer('in-element', {
title: 'me'
});
</script>
<polymer-element>
Run Code Online (Sandbox Code Playgroud)
我希望能够做的是当(任何)元素(放入内容标记中)中的title属性发生更改时(通过单击事件或其他任何内容)调用my元素中的函数.我不知道如何使用观察或如果我需要使用mutationObserver等来访问它.如何完成/是否可能?