我已经设置了与正常的textarea
在聚合物的双向结合使用:
<textarea id="textbox" value="{{editText::input}}" autofocus></textarea>
我也尝试了一个双向绑定iron-autogrow-textarea
使用bindValue属性:
<iron-autogrow-textarea bindValue="{{editText}}" class="fit" autofocus></iron-autogrow-textarea>
属性editText
的分配如下:
Polymer({
is: "page-editor",
properties: {
editText: {
type: String,
value: ""
}
},
但是当改变editText
在代码下面它不会更新各自的文本区域值…
this.editText = "new message";
有趣的是,console.log(this.editText)显示它是'undefined'
正确使用的属性是bind-value="{{editText}}"
。CamelCase属性被转换为带有破折号的属性(source)。
我仍然在增加聚合物,但我认为你需要将notify
设置为true
。
Polymer({
is: "page-editor",
properties: {
editText: {
type: String,
value: "",
+ notify: true
}
},
...
如果这不起作用,发布一个完整的样本,我很乐意和你一起调试。
您可以使用Polymer的on-*
语法添加一个事件侦听器,其中*
是要侦听的事件。
<iron-autogrow-textarea bindValue="{{editText}}"
class="fit"
on-click="f'
autofocus></iron-autogrow-textarea>
定义事件监听器:
Polymer({
is: "page-editor",
properties: {
editText: {
type: String,
value: "",
notify: true
}
},
/* the function signature below may be wrong...
* don't know how many arguments it takes... */
f: function(e, detail, sender) {
this.editText = 'yay';
}
...