如何访问 TextArea 的文本和/或更改它? [英] How to access TextArea's text and/or change it?

查看:48
本文介绍了如何访问 TextArea 的文本和/或更改它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<TextArea id="message"
  maxLength="100"
  width="100%"
  valueLiveUpdate="true"
  showExceededText="false"
  placeholder="Type here.."
  required="true"
/>

控制器

onInit: function() {
  // ...
  this.getView().byId("message").setText("");
},

在这里我尝试了两个命令来清除文本区域值.但是出错了

Here I tried two commands to clear the text area values. But got error

  • this.getView().byId("message").setText("");

TypeError: this.getView(...).byId(...).setText 不是函数

TypeError: this.getView(...).byId(...).setText is not a function

  • sap.ui.getCore().byId("message").setText("");

    类型错误:sap.ui.getCore(...).byId(...) 未定义.

    TypeError: sap.ui.getCore(...).byId(...) is undefined.

  • 如何清除 JS 中的 TextArea 值?

    How to clear TextArea values from JS?

    推荐答案

    控件 sap.m.TextArea 没有 text 属性,因此也没有这样的修改器和访问器.相反,文本值可以通过属性 value 设置,因为控件 扩展 InputBase.

    The control sap.m.TextArea doesn't have the text property and thus no such mutator and accessor either. Instead, the text value can be set via the property value since the control extends InputBase.

    因此,该行应为:

    this.byId("message").setValue();
    

    这篇关于如何访问 TextArea 的文本和/或更改它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆