Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 倾听儿童';使用prototype';聚合物中的s侦听器属性不工作_Javascript_Polymer_Polymer 1.0 - Fatal编程技术网

Javascript 倾听儿童';使用prototype';聚合物中的s侦听器属性不工作

Javascript 倾听儿童';使用prototype';聚合物中的s侦听器属性不工作,javascript,polymer,polymer-1.0,Javascript,Polymer,Polymer 1.0,为什么这行不通? 我试图同时使用notify和侦听器。我错过什么了吗 Polymer({ is: 'x-child', properties: { message: { type: String, value: '', notify: true } } }); Polymer({ is: 'x-dad', listeners: { 'message-changed': '_onMessageReceived'

为什么这行不通? 我试图同时使用
notify
侦听器。我错过什么了吗

Polymer({
  is: 'x-child',

  properties: {
    message: {
      type: String,
      value: '',
      notify: true
    }
  }
});

Polymer({
  is: 'x-dad',

  listeners: {
    'message-changed': '_onMessageReceived'
  },

  _onMessageReceived: function (e) {
    alert('child sent a message');
  }
});
场景

var d = document.createElement('x-dad');
var c = document.createElement('x-child');
d.appendChild(c);
c.message = 'new';

在devguide中,它写道:

当属性更改时,元素将触发一个非冒泡DOM事件,以向感兴趣的主机指示这些更改


这意味着事件侦听器仅在
x-child
元素上调用,而不是在其祖先上调用。这可能是您缺少的。

在您提供的场景中,Polymer如何知道如何将x-dad的消息属性与x-child的消息属性绑定

如果在html中声明x-child,要关联这两个项目,必须声明如下内容: