首页 文章

如何在SAPUI5中将数据从一个视图传递到另一个视图

提问于
浏览
0

主细节模板

单击 Master[list] 时,它将导航到包含表数据的详细信息页面,假设有四列,最后一列中有"Add" Button . 现在我想要的是,点击"Add"按钮,行数据将直接在购物车视图中绑定 .

我尝试使用本地存储,但如何在购物车视图中调用本地存储的数据 .

Cart view is on Master page with icon

On click cart icon view page is this

onPress: function(evt){
    localStorage.setItem('user', JSON.stringify({ 
        a : evt.oSource.oParent.mAggregations.cells[0].mProperties.src,
        b : evt.oSource.oParent.mAggregations.cells[1].mProperties.text,
        c : evt.oSource.oParent.mAggregations.cells[2].mProperties.text,
        d : evt.oSource.oParent.mAggregations.cells[3].mProperties.text 
    })); 
    user = JSON.parse(localStorage.getItem('user'));
}

1 回答

  • 0

    我假设你使用UI5路由器和ODataModel resp在基于组件的应用程序中 . 服务 .

    您可以通过路由将表条目的ID传递到详细信息视图:

    onAddBtnPressed : function(oEv) {
      var oRouter = sap.ui.core.UIComponent.getRouterFor(this),
          oContext = oEv.getSource().getBindingContext("your-model-name"),
          sDetailID = oContext.get("your-id-prop-name");
      oRouter.navTo("detail", {
        detailID: sDetailID
      })
    }
    

    来自routing.config.routes:

    {
      "pattern": "detail/{detailID}",
      "name": "detail",
      "target": "detail"
    }
    

    Note{param} 将参数标记为必需参数,而 :param: 用于可选参数 .

    在您的Detail.controller.js中,在routePatternMatched上注册一个监听器,并按如下方式实现它:

    onRoutePatternMatched: function(oEv) {
      var sDetailID = oEv.getParameter("arguments").detailID;
      // create binding context on detail view
      this.getView().bindElement({
        "/YourDetailSet('"+ sDetailID +'")"
        model: "your-model-name"
      })
      // all the bindings in your detail view will no be relative to the above binding context.
    }
    

相关问题