【发布时间】:2015-08-22 06:42:28
【问题描述】:
我又在修补 Polymer,我想做一些事情,但它不起作用,而且解决方法看起来很混乱。我想为元素设置样式,但要利用数据绑定。基本上我尝试这样做:
<dom-module id="proto-element">
<template>
<style>
#wrapper{
width:{{pixels}};
background: #e1e1e1;
}
#bar{
width:80%;
}
</style>
<div id="wrapper">
<div id="bar" style$={{barStyle}}>I'm the bar! <b>{{test}}</b></div>
</div>
</template>
</dom-module>
<script>
Polymer({
is: "proto-element",
ready: function() {
this.pixels = "300px";
this.test = "Fear me!"
}
});
</script>
绑定到 this.test 的文本完美无缺。但是样式内部的小胡子标签会被忽略。有一个简单的解决方案吗?因为当您使用多个 css 规则时,使用内联样式 $= 语法非常混乱,而且如果您想要的值是在其他地方获得的,您总是需要连接一个字符串才能使其工作。对一个干净的解决方案有什么想法吗?
【问题讨论】:
标签: html data-binding polymer