Создаем таблицу, вызываем метод bindItems, где указываем набор данных (/result в моем случае). Шаблоном здесь является объект ColumnListItem
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
sap.ui.jsview("sapui5_ajax_example.main_view", { /** Specifies the Controller belonging to this View. * In the case that it is not implemented, or that "null" is returned, this View does not have a Controller. * @memberOf sapui5_ajax_example.main_view */ getControllerName : function() { return "sapui5_ajax_example.main_view"; }, /** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed. * Since the Controller is given to this method, its event handlers can be attached right away. * @memberOf sapui5_ajax_example.main_view */ createContent : function(oController) { var oTable = new sap.m.Table("Table", { //headerText: "Product List", itemPress : [ oController.ItemPress, oController ], columns: [ new sap.m.Column({ header: [ new sap.m.Label({ text: "ID" }) ] }), new sap.m.Column({ header: [ new sap.m.Label({ text: "Name" }) ] }), new sap.m.Column({ header: [ new sap.m.Label({ text: "Addr" }) ] }), new sap.m.Column({ header: [ new sap.m.Label({ text: "Dest" }) ] }), ] }); oTable.setMode(sap.m.ListMode.SingleSelectMaster); oTable.bindItems( "/results", new sap.m.ColumnListItem("listItem", { type: "Navigation", cells: [ new sap.m.Text({ text: "{Id}" }), new sap.m.Text({ text: "{Name}" }), new sap.m.Text({ text: "{Addr}" }), new sap.m.Text({ text: "{Dest}" }), ] }) ); var oPage = new sap.m.Page({ title: "Binding Data Example", content: [ oTable ], }); return oPage; } }); |
Здесь все, что между скобками – {Id}, {Name} и т.д. – это наименование полей из метадаты.
Остается только назначить модель в событии инициализации контроллера.
1 2 3 4 5 6 7 8 9 |
var sUrl = "http://host:port/sap/opu/odata/SAP/service_name/"; var oModel = new sap.ui.model.odata.ODataModel(sUrl, false); var oJsonModel = new sap.ui.model.json.JSONModel(); oModel.read("/EmployeeSet?", null, null, true, function(oData, response){ oJsonModel.setData(oData); }); sap.ui.getCore().setModel(oJsonModel); |