Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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
Templates 绑定到同级元素_Templates_Polymer - Fatal编程技术网

Templates 绑定到同级元素

Templates 绑定到同级元素,templates,polymer,Templates,Polymer,我发现不再支持直接绑定到同级元素- 建议的1.0方法适用于属性,但直接绑定到同级元素本身如何,例如: <template> <x-publisher id="publisher"></x-publisher> <x-subscriber publisher="{{$.publisher}}"></x-subscriber> </template> 然后在x-subscriber定义中,您可以执行以下操作: this

我发现不再支持直接绑定到同级元素-

建议的1.0方法适用于属性,但直接绑定到同级元素本身如何,例如:

<template>
  <x-publisher id="publisher"></x-publisher>
  <x-subscriber publisher="{{$.publisher}}"></x-subscriber>
</template>
然后在x-subscriber定义中,您可以执行以下操作:

this.publisher = (new Polymer.IronMeta()).byKey('publisher');
但是,您不能从绑定系统中获得好处,例如,您不能使用Observators数组来观察publisher对象基于路径的属性更改。您可以直接设置对象观察者,但与旧的0.5直接绑定到同级对象的方式相比,开始变得有点混乱


了解这是否只是性能权衡的一部分,但想确认没有更好的方法!另外,如果您想知道绑定到完整元素是否通常是一个性能问题,那就太好了。

您可以这样做:

<template>
  <x-publisher id="publisher"></x-publisher>
  <x-subscriber publisher="{{getElement('publisher')}}"></x-subscriber>
</template>
...
getElement: function(name) { return this.$[name]; }

...
getElement:函数(名称){返回此。$[name];}

在1.0中,这不是您想要做的事情(至少不是以这种方式)。相反,请看一看,这是1.0中跨DOM树共享信息/方法的首选方式。它与的模式相同,允许您在元素/应用程序中的某个位置实例化数据验证器,并在其他位置使用其功能,方法是使用相应的属性指向它。还请注意,与iron meta方法类似,您可以向引用其“this”对象的x-publisher元素添加“self”属性,然后使用“self”属性进行绑定。但不确定绑定到整个元素的性能影响。很好,谢谢。但是,绑定的设置似乎不正确。在x-subscriber中,{{publisher.property}}的任何使用不会随着x-publisher属性的更改而更新,也不会手动配置任何观察者。这是一个bug吗?您不能传递一个元素并期望它的绑定在备用范围内工作,这不是bug
x-subscriber
无法自动收听
publisher
的更新事件。当我仔细考虑后,确定是有意义的,谢谢。只是仔细检查了一下&在0.5中,我们也不能在这里使用声明性绑定,即{{publisher.property}},但是我们可以为传入的元素属性设置一个“observe”对象。如果还可以的话,那就太好了,我发现它非常有用。然而,猜测它可能需要类似Object.observe的东西,哪一个不再使用?
<template>
  <x-publisher id="publisher"></x-publisher>
  <x-subscriber publisher="{{getElement('publisher')}}"></x-subscriber>
</template>
...
getElement: function(name) { return this.$[name]; }