Map json to menu in Openui5

你。 提交于 2019-12-25 02:55:36

问题


In w2ui I can map a json to a sidebar http://w2ui.com/web/demos/#!sidebar/sidebar-1 Can I do it in openui5?

I want the same result.

Obviously I do not want a tree but a list of items that swipe right if I tap on an item (and visualize a sub-menu list) and slide left if I press back button (and visualize the menu at upper level).


回答1:


I think it's possible, but as far as I know you have to do some manual labor:

  1. Detect whether your node has one or more child nodes, and based on that set the sap.m.ListType to Navigation or not
  2. If your root node (f.i., "/items") has child nodes (f.i., "childs"), you need to re-bind your list to this child path ("/items/<index_of_parent_node>/childs)
  3. To get the swiping effect, you probably need to encapsulate the list in a sap.m.Page
  4. Depending on the node level you're in, you need to hide/display your back button, and by pressing it bind your list to the parent path

However, if there's a cleaner, simpler approach I would love to hear it too!




回答2:


I solved my problem: Every time that i click on a menu item i call this function into view controller:

//when click on item
    onPressMenuItem: function(evt) {

        var selectedItem=evt.getSource().getBindingContext().getObject();
        var objAction=getActionWhenPressMenuItem(selectedItem, this.getView().getModel());
        console.log(objAction);

        if(objAction.hasNextSidebar==true){ // sub menu
            var model = new sap.ui.model.json.JSONModel();
            model.setData(objAction.nextSidebar);
            var oSplitApp=sap.ui.core.Core().byId("splitApp");
            var nextView = sap.ui.xmlview("general.master.menuMaster");
            nextView.setModel(model);
            nextView.byId("idPageSidebar").setTitle(selectedItem.text);
            oSplitApp.addMasterPage(nextView);
            oSplitApp.toMaster(nextView);

        }else{ // open operation detail
            var idDetail =objAction.opDetail;
            var targetApp = getAppBySelectionId(idDetail);

            if(targetApp.masterView!=null){//if app has own master
                sap.ui.getCore().getEventBus().publish("navMaster", "to", {
                    idView: targetApp.masterView
                });
            }
            if(targetApp.detailView!=null){//if app has own detail
                sap.ui.getCore().getEventBus().publish("navDetail", "to", {
                    //titleOfDetailPage: selectedItem.text,
                    idView: targetApp.detailView,
                    //idCall: selectedItem
                });
            }   
        } 

    },

I create every time a new istance of the menu on a new page.



来源:https://stackoverflow.com/questions/24207336/map-json-to-menu-in-openui5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!