Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
350 views
in Technique[技术] by (71.8m points)

javascript - 将值从一个函数传递到另一个JS(Passing Value from one function to another JS)

following problem

(以下问题)

I got 2 functions

(我有2个功能)

This is my onInit:

(这是我的onInit:)

onInit: function() {
        sap.ui.core.UIComponent.getRouterFor(this).getRoute("CoObject").attachMatched(this._onRouteMatched, this);
    },

    _onRouteMatched: function(oEvent) {
        var sRoute = oEvent.getParameter("arguments").Route;
    }

and I need to use the Value of sRoute in this function:

(我需要在此函数中使用sRoute的值:)

_onWeiterButtonPress: function(oEvent) {
    var oRouter = this._getRouter();
    var AufNr = this.getView().byId("IptAufNr").getValue();
}

In need sRoute to check which tile the user pressed but I don′t know how to pass the value without setting in global?

(需要sRoute检查用户按下哪个sRoute贴,但是我不知道如何在不设置全局值的情况下传递值吗?)

Thanks for your Help

(谢谢你的帮助)

  ask by BurgGartenKind translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think a solution can be to set the sRoute value on sessionStorage and use it in _onWeiterButtonPress.

(我认为一种解决方案可以是在sessionStorage上设置sRoute值,然后在_onWeiterButtonPress中使用它。)

Here is an example:

(这是一个例子:)

sessionStorage.setItem('sRoute', sRoute);//for set the value
sessionStorage.getItem('sRoute';//for get the value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...