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

发布了6690 篇原创文章 · 获赞 641 · 访问量 110万+

猜你喜欢

转载自blog.csdn.net/i042416/article/details/104370223