Javascript SAPUI5 将焦点设置在输入字段上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33166242/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 14:43:30  来源:igfitidea点击:

SAPUI5 Set Focus on Input Field

javascriptsapsapui5setfocus

提问by Daeron

i have the following Problem:

我有以下问题:

I have 2 XML Views with a few input fields and at navigation to the second view the focus should be on the 5th(ID = "RueckmeldeNr") field.

我有 2 个带有几个输入字段的 XML 视图,在导航到第二个视图时,焦点应该放在第 5 个(ID = "RueckmeldeNr")字段上。

I tried several things but nothing worked.. If i use the jQuery delayedCall the focus shortly flashes on the input field but is instantly set to the NavBack Button in the upper left corner.
Do i use the method false or forget something? How can i solve this?

我尝试了几件事,但没有任何效果。如果我使用 jQuery delayCall,焦点会在输入字段上短暂闪烁,但会立即设置为左上角的 NavBack 按钮。
我是使用 false 方法还是忘记了什么?我该如何解决这个问题?

onAfterRendering : function(oEvent) {
oInputRueck = this.getView().byId("RueckmeldeNr");
//  this.getView().byId("RueckmeldeNr").focus();
//  this.getView().byId("RueckmeldeNr").$().focus();
//  jQuery.sap.delayedCall(200, this, function() {
//      //this.getView().byId("RueckmeldeNr").focus();
//      oInputRueck.focus();
//   });
//  var oFocusInfo = this.getView().byId("RueckmeldeNr").getFocusInfo()
//  this.getView().byId("RueckmeldeNr").applyFocusInfo(oFocusInfo);
    jQuery.sap.delayedCall(0, this, function() {
        oInputRueck.focus();
    });
},

I hope you can help me!
Thank you

我希望你可以帮助我!
谢谢

采纳答案by keshet

Just a suggestion:

只是一个建议:

You could set focus to the required field in the view (or where ever you define it).

您可以将焦点设置到视图中的所需字段(或您定义它的任何地方)。

For example, in view1 you define:

例如,在 view1 中定义:

var oInput = new sap.m.Input({id: "inputID"})
.addEventDelegate({
    onAfterRendering: function(){
        oInput.focus();
    }
});

and then, when you call the view, the focus should be set to the required field automatically.

然后,当您调用视图时,焦点应自动设置为必填字段。

Here is a working JSBIN example: LINK

这是一个有效的 JSBIN 示例:LINK

回答by Daeron

Answer is solved by myself.

答案是我自己解决的。

I just put the delayedCall on 500 miliseconds and it worked.

我只是将 delayCall 设置为 500 毫秒并且它起作用了。

jQuery.sap.delayedCall(500, this, function() {
    this.getView().byId("RueckmeldeNr").focus();
 });