SapUI5:列表项带有另一个列表项的切换(隐藏/显示)

SapUI5: List item with a toggle (hide/show) for another List Item

本文关键字:列表 隐藏 显示 另一个 SapUI5      更新时间:2023-09-26

Hey UI5是一个有很多可能性的框架,但有时我会把想法(在普通HTML中可能更容易)压在墙上。这就是我想要的:一个列表项列表,显示柏林、洛杉矶、莫斯科等城市。在这个列表中,你可以点击一个图标(首选,但也可以是一个按钮)。如果单击图标,则会显示另一个ListItem,从而显示地址。如果你点击该ListItem,你就会得到一个地图——地图部分正在工作,如果它有一个StandardListItem,它就会与列表一起工作。问题是什么?这不利于展示我想要的东西!

示例:

  • 柏林->点击->展示->123456示例街
  • Moskau
  • 洛杉矶

或:

  • 柏林
  • Moskau
  • 洛杉矶->点击->显示->654321示例地址

我的代码:

注意:我删除了一些代码,所以你只能得到它的必要部分

视图:

    <List   id="campusList"
            items="{
                path: '/',
                sorter: {
                    path: 'city',
                    descending: false
                }
            }"
            mode="SingleSelectMaster"
            itemPress="handleListItemPress"
            growing="true">
        <InputListItem  label="{city}" >
            <core:Icon src="sap-icon://navigation-down-arrow" press="showDetails" />
            <StandardListItem type="Navigation" title="{buildingName}" description="{buildingDesc}" />
        </InputListItem>
    </List>

控制器:

jQuery.sap.require("www.adress.com.GeneralHelper");
sap.ui.controller("www.adress.com.LocationList", {
    onInit: function() {
        var bus = sap.ui.getCore().getEventBus();
        bus.subscribe("content", "updateSuccess", this.updateSuccess, this);
        sap.ui.getCore().getEventBus().publish("content", "update", {
            id : "Location"
        });
    },
    updateSuccess: function (channelID , eventID, data) {
        if (data.id === "Location") {
            var oModel = sap.ui.getCore().getModel("LocationModel");
            oModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneWay);
            this.getView().setModel(oModel);
            if (!jQuery.device.is.phone) {
                //preselect entry
                var self = this;
                var oList = this.byId("campusList");
                oList.attachUpdateFinished(function(evt) {
                    if (oList.getItems().length > 0) {
                        var oContext = new sap.ui.model.Context(self.getView().getModel(), "/0");
                        oList.setSelectedItem(oList.getItems()[0], true);
                        sap.ui.getCore().getEventBus().publish("nav", "to", {
                            id: "LocationDetail",
                            data : oContext
                        });
                    }
                });
            }
        }
    },
    handleListItemPress : function (evt) {
        sap.ui.getCore().getEventBus().publish("nav", "to", {
            id : "LocationDetail",
            data : evt.getParameters().listItem.getBindingContext()
        });
    }
});

我还有一个从UpdateHelper加载的本地演示数据json。

附言:我不想使用$().hide、$().show和其他jquery,我更喜欢UI5。

如果您想显示或隐藏列表项,可以使用

myListItem.setVisible(true) //or
myListItem.setVisible(false)

但您也可以使用自定义列表项,将所有额外信息放入new sap.m.Panel()中,并在单击时将该Panel添加到您的自定义列表项中(并将其销毁/设置为不可见以隐藏额外信息)。