简体   繁体   English

聚合物1.0与文本区域的双向绑定

[英]Polymer 1.0 two-way binding with textarea

I have this simple two-way data binding with textarea: 我有这个简单的双向数据绑定与textarea:

<dom-module id="my-element">
  <style>
  </style>

  <template>
    <button on-click="click">Click me!</button>
    <textarea>{{element}}</textarea>
  </template>
</dom-module>

<script>
  Polymer({
    is: "my-element",

    properties: {
      element: {
        type: String,
        value: "Default value",
        notify: true
      }
    },

    click: function() {
      console.log(this.element);
    }
  });
</script>

The textarea show up with "Default Value". 文本区域显示为“默认值”。 When I change this value and then click on the button, the console still log out Default value instead of the text that I just typed in. What did I do wrong here? 当我更改此值然后单击按钮时,控制台仍注销“ Default value而不是我刚刚输入的文本。在这里,我做错了什么?

You should use <iron-autogrow-textarea> to allow data binding. 您应该使用<iron-autogrow-textarea>允许数据绑定。

<dom-module id="my-element">
  <style>
  </style>

  <template>
    <button on-click="click">Click me!</button>
    <iron-autogrow-textarea bind-value="{{element}}"></iron-autogrow-textarea>
  </template>
</dom-module>

<script>
  Polymer({
    is: "my-element",

    properties: {
      element: {
        type: String,
        value: "Default value",
      }
    },

    click: function() {
      console.log(this.element);
    }
  });
</script>
</dom-module>

Documentation is here . 文档在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM