我已经在聚合物中建立了与普通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时,它不会更新相应的textarea值.
this.editText = "new message";有趣的是,console.log(this.editText)说它的“未定义”
发布于 2015-08-14 07:55:42
要使用的正确属性是bind-value="{{editText}}"。CamelCase属性被转换为带有破折号(来源)的属性。
发布于 2015-08-13 18:23:29
我还在研究聚合物,但我认为你需要将notify设置为true。
Polymer({
is: "page-editor",
properties: {
editText: {
type: String,
value: "",
+ notify: true
}
},
...如果这不起作用,发布一个完整的示例,我将很乐意与您一起调试。
您可以使用聚合物的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';
}
...https://stackoverflow.com/questions/31994311
复制相似问题