代码之家  ›  专栏  ›  技术社区  ›  Swappy

无法对sapui5中的多个字段应用搜索

  •  1
  • Swappy  · 技术社区  · 6 年前

    Contacts.controller.js:联系人:

            sap.ui.define([
            "sap/ui/core/mvc/Controller",
            "sap/ui/model/json/JSONModel",
            "sap/ui/model/Filter",
            "sap/ui/model/FilterOperator"
    
        ], function(Controller,JSONModel,Filter,FilterOperator) {
            "use strict";
    
            return Controller.extend("ContactsList.controller.Contacts", {
    
            onFilterContacts : function (oEvent) {
    
                var aFilter = [];
                    var aFilter1 =[]; 
                    var tFilter=[];
                    var sQuery = oEvent.getParameter("query");
    
                        aFilter.push(new Filter("Name", FilterOperator.Contains, sQuery));
                        aFilter1.push(new Filter("Phone No.", FilterOperator.Contains, sQuery));
                             tFilter = new Filter([aFilter,aFilter1],false);  
    
    
                    // filter binding
                    var oList = this.byId("contactList");
                    var oBinding = oList.getBinding("items");
                    oBinding.filter(tFilter);
                }
    
            });
    
        });
    

    Contacts.view.xml文件:

            <mvc:View controllerName="ContactsList.controller.Contacts" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" 
            xmlns:html="http://www.w3.org/1999/xhtml">
            <List id="contactList" class="sapUiLargeMarginLeft sapUiLargeMarginRight" width="auto" items="{contact>/ContactList}">
                <headerToolbar>
                 <Toolbar>
    
                    <ToolbarSpacer/>
                    <SearchField width="50%" search="onFilterContacts"/>
                 </Toolbar>
              </headerToolbar>
                <items>
                    <ObjectListItem title="{contact>Name}" number="{contact>Phone No.}"></ObjectListItem>
                </items>
            </List>
        </mvc:View>
    

            {
                  "ContactList": [
                    {
                      "Name": "Swapnil Garg",
                      "Phone No.": 1234
                    },
                    {
                       "Name": "Ashutosh Garg",
                      "Phone No.": 5678
                    },
                    {
                       "Name": "Rajat Sharma",
                      "Phone No.": 1987
                    },
                    {
                      "Name": "Ankur Shukla",
                      "Phone No.": 6789
                    },
                    {
                       "Name": "Naman Kumar",
                      "Phone No.": 2345
                    }
                  ]
                }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Matthijs Mennens    6 年前

    只有 String 值受支持 sap.ui.model.FilterOperator.Contains

    控制器

        onFilterContacts: function(oEvent) {
        var sQuery = oEvent.getParameter("query");
    
        var oFilter1 = new Filter("Name", FilterOperator.Contains, sQuery);
        var oFilter2 = new Filter("Phone No.", FilterOperator.Contains, sQuery);
        var arrFilter = new Filter([oFilter1, oFilter2], false);
    
        // filter binding
        var oList = this.byId("contactList");
        var oBinding = oList.getBinding("items");
        oBinding.filter(arrFilter);
    }
    

    联系人列表.json

    {
      "ContactList": [
        {
          "Name": "Swapnil Garg",
          "Phone No.": "1234"
        },
        {
           "Name": "Ashutosh Garg",
          "Phone No.": "5678"
        },
        {
           "Name": "Rajat Sharma",
          "Phone No.": "0987"
        },
        {
          "Name": "Ankur Shukla",
          "Phone No.": "1342"
        },
        {
           "Name": "Naman Kumar",
          "Phone No.": "1928"
        }
      ]
    }