• 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的原创文章,请关注公众号"汪子熙":

  • 相关阅读:
    图片压缩后,依然很大的解决方案
    怎么使用javascript实现类的功能
    javascript实现像java、c#之类的sleep暂停的函数功能
    用ajax和asp.net实现智能搜索功能
    insert into 和insert into select性能比较
    百度编辑器
    document.selection.createRange()
    CSS设置透明效果
    class中一个小技巧
    asp.net中 解析JSON
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/12332074.html
Copyright © 2020-2023  润新知