SAPUI5教程——Aggregation Binding的应用

来源:互联网 发布:淘宝换货小二介入 编辑:程序博客网 时间:2024/06/17 09:03

前言

对于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 descendingvar 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 sortingoTable.getBinding("rows").sort(oSorter);// manual filteringoTable.getBinding("rows").filter([oFilter1,oFilter2,oFilter3]);oComboBox.getBinding("items").filter([oFilter1,oFilter2,oFilter3]);