是否必须在Polymer.dart中支持小胡子绑定? [英] Is imperative Mustache-Binding in Polymer.dart supported?

查看:85
本文介绍了是否必须在Polymer.dart中支持小胡子绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

强制我不能得到一个胡子绑定工作在一个polymer.dart组件:

imperatively i am not able to get a mustache-binding to work in a polymer.dart component:

...
@observable String data = "testData";
...
ready() {
  Element container = this.shadowRoot.querySelector("#container");    
  DocumentFragment newFragement = this.createFragment("<sample-element myAttribute='{{data}}'></sample-element>");
  container.nodes.add(newFragement);
}

不解释胡子绑定,一个解决方法,我发现是这一个,但我不知道这是否是最好的方法做到这一点,缺点是我不能使用mustache绑定的命令式比:

the mustache binding is not interpreted, a workaround i found is this one, but i dont know if this is the preferred way to do it and the downside is that i cannot use the mustache-binding imperatively than:

Element newElement = new Element.tag("sample-element");
nodeBind(newElement).bind("myAttribute", new PathObserver(this, "data"));
container.nodes.add(newElement);

欢迎任何想法! : - )

Any thoughts welcome! :-)

推荐答案



Polymer.dart有 injectBoundHtml()自那以来

<div id="container"></div>

...

this.injectBoundHtml('<foo-bar baz="{{qux}}"></foo-bar>', this.$['container']);

另请参阅 http://stackoverflow.com/a/25982843/217408

Justin Fagnani提供了解决方法 https:// groups .google.com / a / dartlang.org / d / msg / web / DYD1NA-SH0A / h-hSU3J8nDYJ

Justin Fagnani provided a workaround https://groups.google.com/a/dartlang.org/d/msg/web/DYD1NA-SH0A/h-hSU3J8nDYJ

另请参阅此问题 https://code.google.com/p/dart/issues/detail?id= 19875


是的,问题是所有这些绑定和PathObservers实际上是反射的。我们使用烟作为实现反射API的库。当你在Dartium中运行时,这个API是用dart:mirror实现的,但是当你使用聚合变换器构建应用程序时,我们用生成的代码来替换镜像,帮助dart2js优化你的应用程序。

Yeah, the problem is that all these bindings and PathObservers are actually reflective. We use smoke as a library that implements the reflective API. When you run in Dartium, this API is implemented with dart:mirrors, but when you build the app with the polymer transformers, we replace the use of mirrors with generated code to help dart2js optimize your app.

为了生成我们需要的代码,聚合变换器解析你的应用程序,发现模板中的每个表达式,等等。 Dart代码中的表达式,如上面的示例,没有被发现,所以我们不知道如何为它们生成代码。这基本上是为什么没有#commands或#save的条目。

To generate the code we need, the polymer transformers parse your app and discover every expression in a template, among other things. Expressions within Dart code, like your example above, are not discovered so we don't know how to generate code for them. That's basically why there is no entry for #commands or #save.

在未来我想添加一个选项,添加自己的变压器阶段,告诉烟雾生成一些额外的符号等,但是今天不可用。

In the future I'd like to add the option of adding your own transformer phase that tells smoke to generate some extra symbols and such, but this is not available today.

同时,解决这个问题的最好方法是确保这些符号在你的HTML模板。它应该足以定义一个聚合物元素的元素,其模板使用那些符号(即使该元素不在任何地方使用)。

Meanwhile, the best way to work around this issue is to make sure those symbols are mentioned in your HTML templates somewhere. It should be enough to define a polymer-element element whose template uses those symbols (even if the element is not used anywhere).

这篇关于是否必须在Polymer.dart中支持小胡子绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆