繁体   English   中英

如何通过sapui5中的控制器过滤列表

[英]How to filter a list via controller in sapui5

我是SAPUI5的新手,我的App有点问题。 我设置了一个主从应用程序,该应用程序在主视图中显示了一个客户列表。 我的目标是将该列表筛选为oData服务的任何属性(我正在使用Northwind Web服务)。

在这里,您可以看到带有我的视图列表的代码段(MasterView.xml):

<List
            id="list"
            items="{
                path: '/Customers',
                sorter: {
                    path: 'CompanyName',
                    descending: false
                },
                groupHeaderFactory: '.createGroupHeader'
            }"
            busyIndicatorDelay="{masterView>/delay}"
            noDataText="{masterView>/noDataText}"
            mode="{= ${device>/system/phone} ? 'None' : 'SingleSelectMaster'}"
            growing="true"
            growingScrollToLoad="true"
            updateFinished="onUpdateFinished"
            selectionChange="onSelectionChange">
            <infoToolbar>
                <Toolbar
                    active="true"
                    id="filterBar"
                    visible="{masterView>/isFilterBarVisible}"
                    press="onOpenViewSettings">
                    <Title
                        id="filterBarLabel"
                        text="{masterView>/filterBarLabel}" />
                </Toolbar>
            </infoToolbar>
            <items>
                <ObjectListItem
                    type="{= ${device>/system/phone} ? 'Active' : 'Inactive'}"
                    press="onSelectionChange"
                    title="{CompanyName}"
                    numberUnit="{CustomerID}">
                </ObjectListItem>
            </items>
        </List>

这是我在控制器(Master.controller.js)中所做的事情:

onInit : function () {
            // Control state model
            var oList = this.byId("list"),
                oViewModel = this._createViewModel(),
                // Put down master list's original value for busy indicator delay,
                // so it can be restored later on. Busy handling on the master list is
                // taken care of by the master list itself.
                iOriginalBusyDelay = oList.getBusyIndicatorDelay();
            // Tryout Filter
            var equals = FilterOperator.EQ;
            var aFilterFoo = [];
            aFilterFoo.push(new Filter("Country", equals, "Germany"));
            var oBinding = oList.getBinding("items");
            oBinding.filter(aFilterFoo); 
            // End tryout Filter

            this._oList = oList;
            // keeps the filter and search state
            this._oListFilterState = {
                aFilter : [],
                aSearch : []
            };


            this.setModel(oViewModel, "masterView");
            // Make sure, busy indication is showing immediately so there is no
            // break after the busy indication for loading the view's meta data is
            // ended (see promise 'oWhenMetadataIsLoaded' in AppController)
            oList.attachEventOnce("updateFinished", function(){
                // Restore original busy indicator delay for the list
                oViewModel.setProperty("/delay", iOriginalBusyDelay);
            });

            this.getView().addEventDelegate({
                onBeforeFirstShow: function () {
                    this.getOwnerComponent().oListSelector.setBoundMasterList(oList);
                }.bind(this)
            });

            this.getRouter().getRoute("master").attachPatternMatched(this._onMasterMatched, this);
            this.getRouter().attachBypassed(this.onBypassed, this);

        },

所有这些都是由SAP Web IDE自动设置的。 我只在注释// Tryout Filter和// End Tryout之间更改了代码

当我想运行我的应用程序时,调试器会说:“无法读取未定义的属性'filter'”,因为oBinding是未定义的。 希望大家能帮助我。

非常感谢和最诚挚的问候

通过使用树液生命周期方法解决了此问题。 onBeforeRendering()是我在Master.Controller.js中使用的函数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM