如何将数据从母版页传递到详细信息页面SAPUI5?

时间:2015-06-06 13:18:07

标签: javascript sap sapui5 sap-fiori

我想按ListItem

将参数从母版页传递到详细页面
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);
},

我想获取参数详细信息页onInit函数。

2 个答案:

答案 0 :(得分:5)

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

答案 1 :(得分:1)

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

在掌握中,当你传递参数时,写下:

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

进入Detail控制器,在init函数中添加:

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 ...)