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

时间:2015-06-22 11:54:35

标签: javascript list sapui5

嘿UI5是一个有很多可能性的框架,但有时我会对墙壁上的想法(在普通的HTML中可能更容易)进行粉碎。 这就是我想要的:带有ListItems的列表,例如显示城市,例如柏林,洛杉矶,莫斯科等。听完之后你可以点击一个图标(首选,但也可以是一个按钮)。如果单击图标,则显示另一个ListItem,以便显示一个地址。如果你然后舔那个ListItem你会得到一个地图 - 地图部分正在工作,如果它有一个StandardListItem它将适用于该列表。问题?显示我想要的东西是不好的!

示例:

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

或:

  • 柏林
  • Moskau的
  • 洛杉矶 - >点击 - > show - > 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加载的local-demo-data-json。

PS:我不想使用$()。hide,$()。show和其他jquery的东西,我更喜欢UI5。

1 个答案:

答案 0 :(得分:1)

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

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

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