//创建List
var homeCategoryTable = new sap.m.List("homeCategoryTable", {
headerText : "Categories"
});
//绑定Aggregation,List的sname必须是items,path下面必须是数组,template是行模版
homeCategoryTable.bindAggregation("items", {
path : "/category",
template : new sap.m.StandardListItem({
title : "{CategoryName}",
counter : "{NumberOfProducts}"
})
});
//创建Model
var productCategoryModel = new sap.ui.model.json.JSONModel(
"model/ProductCategory.json");
homeCategoryTable.setModel(productCategoryModel);
ProductCategory.json内容
{"category" : [
{
"CategoryName" : "Accessories",
"Category" : "AC",
"NumberOfProducts" : 5
}, {
"CategoryName" : "Flat Screens",
"Category" : "FS",
"NumberOfProducts" : 3
}, {
"CategoryName" : "Graphics Cards",
"Category" : "GC",
"NumberOfProducts" : 3
}, {
"CategoryName" : "Keyboards",
"Category" : "KB",
"NumberOfProducts" : 2
}, {
"CategoryName" : "Laptops",
"Category" : "LT",
"NumberOfProducts" : 1
}, {
"CategoryName" : "Printer",
"Category" : "PR",
"NumberOfProducts" : 2
}
]
}
在controller中获得数据
var filters = [];
var query = event.getParameter("query");
if (query && query.length > 0) {
var filter = new sap.ui.model.Filter("CategoryName",
sap.ui.model.FilterOperator.Contains, query);
filters.push(filter);
}
var list = sap.ui.getCore().byId("homeCategoryTable");
var binding = list.getBinding("items");
binding.filter(filters);