SAPUI5教程——Aggregation Binding的应用
Posted 天外野草
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SAPUI5教程——Aggregation Binding的应用相关的知识,希望对你有一定的参考价值。
前言
对于SAPUI5的程序开发而言,通常我们会使用XML View, 但是在某种特殊情况下,需要动态绑定数据,或者声场动态view, 这个时候难免会使用JS 去处理,因此 Aggregation Binding的用法,我们一定要有所了解。
数据模型绑定
我们以一个combox为例: 如果用js view,可以使用如下代码。
var oItemTemplate = new sap.ui.core.ListItem(text:"name");
var oComboBox = new sap.ui.commons.ComboBox(
items:
path: "/company/contacts",
template: oItemTemplate
);
如果使用Aggregation binding 的方式,可以按照如下方式:
oComboBox.bindAggregation("items", "/company/contacts", new sap.ui.core.ListItem(text:"name"));
解除绑定:
oComboBox.unbindAggregation("items");
Filter 和sorter的使用
var oSorter = new sap.ui.model.Sorter("name", true); // sort descending
var oFilter1 = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.StartsWith, "M");
var oFilter2 = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.Contains, "Paz");
var oFilter3 = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.BT, "A","G"); // name between A and G
// manual sorting
oTable.getBinding("rows").sort(oSorter);
// manual filtering
oTable.getBinding("rows").filter([oFilter1,oFilter2,oFilter3]);
oComboBox.getBinding("items").filter([oFilter1,oFilter2,oFilter3]);
以上是关于SAPUI5教程——Aggregation Binding的应用的主要内容,如果未能解决你的问题,请参考以下文章
Node.jsmongoose教程10--聚合(Aggregation)的应用
SAP UI5 设备类型检测 Device API 的工作原理