简体   繁体   English

如何使用javascript重置sap ui5输入字段?

[英]How to reset sap ui5 input fields by using javascript?

i have created one submission form by using java script i need to reset the input data by using on reset button.我已经使用 java 脚本创建了一个提交表单,我需要使用重置按钮来重置输入数据。 Help me out of this.帮我解决这个问题。

reset: function() {
    var oInput1 = sap.ui.getCore().byId("firstname");
    oInput1.setValue("");*/
    this.getViewById("firstname").setValue("");*/
}

    input1.getId("firstname").setValue("");

onExit: function() {
    input1.setValue("");
}

the code is not resetting the form data代码未重置表单数据

First of all your provided code-sample is incorrect, please correct it.首先,您提供的代码示例不正确,请更正。

Second, onExit is executed when your view is destroyed, setting the input value to empty is rather useless there.其次, onExit在您的视图被销毁时执行,将输入值设置为空在那里相当无用。

If you want to reset data of your input-field when clicking a button you'll need to have the following elements:如果要在单击按钮时重置输入字段的数据,则需要具有以下元素:

1) an Input - & Button -control (with press-event) in your XML-view. 1) 在您的 XML 视图中输入- &按钮 -控件(带有按下事件)。

2) an id assigned to your Input-control to be able to refer to the control when pressing the reset-button. 2) 分配给您的输入控件的 id,以便在按下重置按钮时能够引用该控件。

3) The press-event from the button worked out in your controller. 3)来自按钮的按下事件在您的控制器中产生。

XML XML

<Input id="firstname" value=""/>
<Button text="Reset" press="reset"/>

Controller控制器

reset: function() {
    var oInput1 = this.getView().byId("firstname");
    oInput1.setValue("");
}

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

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