了解聚合物数据绑定和HTML标签 [英] Understanding Polymer data-binding and HTML tags
问题描述
< span> {{var}}< / span>
如果没有,变量根本就不会展开和打印。
一个示例(来自 Polymer Quick Tour ),一行更多的显示这个行为。您还可以在 Plunker 上找到它。
< dom-module id =name-tag>
< template>
<! - 将打印:这是{{owner}}的name-tag元素。 - >
这是{{owner}}的name-tag元素。< br />
<! - 将打印:这是丹尼尔的名称标签元素。 - >
这是< b> {{owner}}< / b>的name-tag元素。
< / template>
< / dom-module>
< script>
聚合物({
是:name-tag,
ready:function(){
//设置此元素的所有者属性
this.owner =Daniel ;
}
});
< / script>
我错过了文档中的某些内容,还是这种错误?
今天读这个问题的那个
这个行为似乎已经修复,在Plunkr的例子中没有问题
解决方案根据 docs :
绑定注释当前必须覆盖标签的整个内容。
这意味着您目前必须将绑定包装在标签中你在这个例子中做到了:
这是< b> {{owner}}< / b>的name-tag元素。
我希望将来会更改这个内容,以便您不必在标签中包装绑定。
I'm new to Polymer and while testing data-binding, I discover that I have to encapsulate double-mustache expressions within HTML tags (for example <span>{{var}}</span>
).
If not, variable is simply not expanded and printed as is.
An exemple (from Polymer Quick Tour), with a line more to show this behaviour. You can also find it on Plunker.
<dom-module id="name-tag">
<template>
<!-- Will print : This is {{owner}}'s name-tag element. -->
This is {{owner}}'s name-tag element.<br />
<!-- Will print : This is Daniel's name-tag element. -->
This is <b>{{owner}}</b>'s name-tag element.
</template>
</dom-module>
<script>
Polymer({
is: "name-tag",
ready: function() {
// set this element's owner property
this.owner = "Daniel";
}
});
</script>
Did I miss something on the documentation, or is this some kind of bug ?
To the ones that reads this question today
This behavior seems to have been fixed, in the example on Plunkr, there is no problem anymore.
解决方案 According to the docs :
The binding annotation must currently span the entire content of the tag.
This means you currently have to wrap your bindings in a tag as you did in this example:
This is <b>{{owner}}</b>'s name-tag element.
I expect in the future this will be changed so that you don't have to wrap bindings in a tag.
这篇关于了解聚合物数据绑定和HTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!