zoukankan      html  css  js  c++  java
  • SAP UI5应用里搜索功能的实现

    在一个包含了list的XML视图里,使用SearchField标签页定义一个搜索按钮。点击之后,执行的事件处理函数为handleSearch:

    <mvc:View controllerName="sapcp.cf.tutorial.app.controller.View1" xmlns:mvc="sap.ui.core.mvc" displayBlock="true" xmlns="sap.m">
    	<Shell id="shell">
    		<App id="app">
    			<pages>
    				<Page id="page" title="{i18n>title}">
    					<subHeader>
    						<Bar>
    							<contentLeft>
    								<SearchField search="handleSearch"/>
    							</contentLeft>
    						</Bar>
    					</subHeader>
    					<content>
    						<List id="List" items="{/Products}">
    							<ObjectListItem type="Navigation" press="handleListItemPress" title="{ProductName}" number="{= ((${UnitPrice} * 100) / 100).toFixed(2) }"
    								numberUnit="{i18n>currency}">
    								<attributes>
    									<ObjectAttribute text="{QuantityPerUnit}"/>
    								</attributes>
    								<firstStatus>
    									<ObjectStatus text="{= ${Discontinued}? 'Discontinued' : 'Available' }" state="{= ${Discontinued}? 'Error' : 'Success' }"/>
    								</firstStatus>
    							</ObjectListItem>
    						</List>
    					</content>
    				</Page>
    			</pages>
    		</App>
    	</Shell>
    </mvc:View>
    

    在视图的控制器里实现这个搜索函数:

    
    sap.ui.define([
    	"sap/ui/core/mvc/Controller",
    	"sap/m/MessageBox"
    ], function (Controller, MessageBox) {
    	"use strict";
    
    	return Controller.extend("sapcp.cf.tutorial.app.controller.View1", {
    		onInit: function () {
    
    		},
    
    		// show in a pop-up which list element was pressed
    		handleListItemPress: function (oEvent) {
    			var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
    			var selectedProductId = oEvent.getSource().getBindingContext().getProperty("ProductID");
    			oRouter.navTo("Detail", {
    				productId: selectedProductId
    			});
    		}
    	});
    });
    

    测试:

    搜索能够按照期望的工作:

    要获取更多Jerry的原创文章,请关注公众号"汪子熙":

  • 相关阅读:
    代码习惯
    全网最详细的fhq treap (非旋treap)讲解
    按位或「HAOI2015」
    列队「NOIP2017」
    愤怒的小鸟「NOIP2016」
    能量传输「CSP多校联考 2019」
    矿物运输「CSP多校联考 2019」
    普通打击「CSP多校联考 2019」
    普通快乐「CSP多校联考 2019」
    BZOJ4385: [POI2015]Wilcze doły
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/12332074.html
Copyright © 2011-2022 走看看