2015-06-06 110 views
3

我想從母版頁參數傳遞給詳細信息頁面上的ListItem如何將數據從主頁面傳遞到詳細信息頁面SAPUI5?

我想要得到的參數細節頁 onInit功能
handleListItemPress : function (evt) { 

imp = evt.getSource().getTitle(); 
    alert(imp); 

// var mystring = 'this,is,an,example'; 
    var splits = imp.split(","); 


    dino  = splits[0]; //I want to send three parameters 
    revno = splits[1]; 
    uruntipi = splits[2]; 

    var context = evt.getSource().getBindingContext(); 
    this.nav.to("Detail", context); 
}, 

按。

+0

可能重複的[UI5 - 視圖之間傳遞數據](https://stackoverflow.com/questions/34000949/ui5-passing-data-between-views) – boghyon

回答

4
handleListItemPress: function (evt) { 
    var imp = evt.getSource().getTitle(); //don't declare globals variables 
    // var mystring = 'this,is,an,example'; 
    var splits = imp.split(","); 

    //build json object with all your properties you want to send 
    var context = { 
     dino: splits[0], 
     revno: splits[1], 
     uruntipi = splits[2], 
     bindingContext = evt.getSource().getBindingContext() 
    }; 

    this.oRouter.navTo("Detail", context); 
    //OR sap.ui.core.UIComponent.getRouterFor(this).navTo("Detail", context); 
    //this.nav.to("Detail", context); 
} 

詳細頁:

onInit: function() { 
    var oRouter = sap.ui.core.routing.Router.getRouter("appRouter"); 
    //can also use directly this.oRouter.attachRouteMatched(...) 
    oRouter.attachRouteMatched(function (oEvent) { 
     if (oEvent.getParameter("name") !== "detail") { 
      return: 
     } 
     var dino = oEvent.getParameter("arguments").dino; 
     var revno = oEvent.getParameter("arguments").revno; 
     var uruntipi = oEvent.getParameter("arguments").uruntipi; 
     var bindingContext = oEvent.getParameter("arguments").bindingContext; 
    }, this); 
} 

在這裏閱讀更多Methods and Events for Navigation

+0

嗨Sunil,謝謝你的回答,但得到錯誤不能讀屬性'attachRouteMatched'並不能解決這個問題。你有什麼想法嗎? –

+0

您是否在使用腳手架/底座控制器來實現主細節模式? –

+0

我只使用你的代碼。我有做配置嗎? –

1

如果你不想使用路由可以使用事件總線。 https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.core.EventBus.html

在主,當你有PARAMS通過,寫:

this.bus = sap.ui.getCore().getEventBus(); 
this.bus.publish("channel1", "eventA" , { 
       par1: 4324, 
       par2: 23423, 
       par3: 12331 
      }); 

細說控制器,在初始化函數中添加:

this.bus = sap.ui.getCore().getEventBus(); 
    this.bus.subscribe("channel1", "eventA", this._manageData, this); 

,並添加一個功能:

_manageData: function (channel1, eventA, data) { 
    //here data contains par1, par2, par3   
}, 

但在更多視圖中使用相同數據的正確方法是使用模型(JSONModel ...)

相關問題