![](/img/trans.png)
[英]Passing a value from one function to another function in React.js
[英]Passing Value from one function to another JS
以下問題
我有2個功能
這是我的 onInit:
onInit: function() {
sap.ui.core.UIComponent.getRouterFor(this).getRoute("CoObject").attachMatched(this._onRouteMatched, this);
},
_onRouteMatched: function(oEvent) {
var sRoute = oEvent.getParameter("arguments").Route;
}
我需要在此函數中使用sRoute
的值:
_onWeiterButtonPress: function(oEvent) {
var oRouter = this._getRouter();
var AufNr = this.getView().byId("IptAufNr").getValue();
}
需要sRoute
來檢查用戶按下了哪個圖塊,但我不知道如何在不設置全局的情況下傳遞值?
感謝您的幫助
我認為一個解決方案是在 sessionStorage 上設置 sRoute 值並在 _onWeiterButtonPress 中使用它。 這是一個例子:
sessionStorage.setItem('sRoute', sRoute);//for set the value
sessionStorage.getItem('sRoute';//for get the value
這個怎么樣:
_onRouteMatched: function (oEvent) {
var sRoute = getArgumentsFromRoute(oEvent);
}
_onWeiterButtonPress: function (oEvent) {
var oRouter = this._getRouter();
var AufNr = this.getView().byId("IptAufNr").getValue();
var sRoute = getArgumentsFromRoute(oEvent);
}
function getArgumentsFromRoute(oEvent)
{
return oEvent.getParameter("arguments").Route;
}
您可以將對象作為 navTo 方法的第二個參數傳遞。
onWeiterPressed: function (oEvent) {
this.getRouter().navTo("detailView", {
aufNr: this.getView().byId("IptAufNr").getValue();
});
},
然后在您導航到的視圖中:
_onRouteMatched: function (oEvent) {
// Get passed object
var sObjectId = oEvent.getParameter("arguments").aufNr;
},
全部寫在文檔中;)
通過聲明在@santhosh 的幫助下解決了它
_onRouteMatched: function(oEvent) {
this.sRoute = oEvent.getParameter("arguments").Route;
}
現在我可以從一個視圖導航到 3 個不同的視圖,具體取決於用戶單擊的 Tile。
多謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.