结合势在必行 [英] Binding imperatively
问题描述
有没有一种方法来设置绑定势在必行。一个例子用例:
Is there a way to set up bindings imperatively. An example use case:
var el2 = new MyElement();
el2.myProp = this.$.anotherElement.anotherProp
这不会设置绑定,它只是将值或对象。我想找到一种方法,这样做:
That won't setup a binding, it just assigns the value or object. I'd like to find a way to do something like:
el2.myProp.bindTo(this.$.anotherElement.anotherProp)
可能?
推荐答案
聚合物1.0不目前支持该特性 - 正如@kevinpschaaf在Github上的 https://github.com/Polymer/polymer/issues/1778 。
Polymer 1.0 does not support this at the moment - as explained by @kevinpschaaf in Github https://github.com/Polymer/polymer/issues/1778.
(由@kevinpschaaf评论)
(comment by @kevinpschaaf)
不,我们目前不支持此功能,DOM绑定之外,这是
只有模板实现,后期结合实例的孩子。您
可以使用document.createElement('模板','DOM捆绑'),那么你就可以
动态附加儿童约束注释的内容,
而绑定将只计算一次的DOM绑定连接
到文档。看到这里测试,证明它的这种用法:
https://github.com/Polymer/polymer /blob/master/test/unit/dom-bind.html#L95
No, we don't currently support this, outside of dom-bind, which is the only template implementation that late-binds instance children. You can document.createElement('template', 'dom-bind'), then you can dynamically append children with binding annotations to its content, and the bindings will only be evaluated once the dom-bind is attached to the document. See tests here that show this usage of it: https://github.com/Polymer/polymer/blob/master/test/unit/dom-bind.html#L95
需要注意的是DOM绑定目前不允许绑定到外部范围,所以
它具有自定义元素模板有限使用(它的主要用途的情况是
在主文档中)的元素之间的结合,而不是
可能改变短期的。
Note that dom-bind does not currently allow binding to outer scope, so it has limited use in custom element templates (it's main use case is for binding between elements in the main document), and that's not likely to change short-term.
我们通过烘烤获得了很多的性能优化
绑定连接到原型在报名时间为
元素(而不是实例时),我们还没有建立足够的
机械的,很容易让运行时添加/删除绑定。
We are achieving a lot of performance optimization by baking the binding connections into the prototype at registration time for an element (rather than at instance time), and we haven't built up enough of the machinery to easily allow runtime addition/removal of bindings.
这篇关于结合势在必行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!