标准Tiles显示数据库表中存在的特定记录数

时间:2016-08-10 11:46:24

标签: sapui5

我正在尝试在tile容器中创建一个带有标准tile的页面,显示在该视图中调用的表中存在的记录数(已批准/已拒绝/未决),而不是完整表的条目。

以下代码显示整个表中的记录。

以下是代码:

tiletest.view.js

var oDataModel = new sap.ui.model.odata.ODataModel("https://.../tiletest/tile.xsodata", true);

var items;
oDataModel.read("/Expense", null, null, false, function success(oData) {
        items = oData.results.length;
    },
    function failure() {});
var page1 = new sap.m.Page("page1", {
        showHeader: false
    }),
    content: [
        new sap.m.TileContainer({
            tiles: [
                new sap.m.StandardTile("tile", {
                    title: "Request",
                    info: "Create Request",
                    infoState: "Success",
                    press: function() {
                        oController.ab();
                    }
                }),
                new sap.m.StandardTile("tile1", {
                    number: items,
                    title: "Approved",
                    info: "Approved Requests",
                    infoState: "Success",
                    press: function() {
                        oController.appr();
                    }
                }),
                new sap.m.StandardTile("tile2", {
                    number: items,
                    title: "Rejected",
                    info: "Rejected Request",
                    infoState: "Warning",
                    press: function() {
                        oController.appr1();
                    }
                })
            ]
        })
    ]
});

return page1;
}

tiletest.controller.js

sap.ui.controller("test1.tiletest", {
    ab: function() {
        var app = sap.ui.getCore().byId("AppID");
        app.to("list_id2");
    },

    ab2: function() {
        var app = sap.ui.getCore().byId("AppID");
        app.to("list_id6");
    },

    appr: function() {
        var app = sap.ui.getCore().byId("AppID");
        app.to("list_id4");
    }
}); 

tile.xsodata

service{
"DATABASE_NAME"."TABLE_NAME" as "Expense";
 }

2 个答案:

答案 0 :(得分:1)

要显示已批准或已拒绝的请求数,您必须运行2个ODataModel.read语句,这些语句根据正确的过滤器获取$ count。 E.g:

// These filters are the filters that should be applied to your tile count
var _mFilters = {
    approved: [new sap.ui.model.Filter("Approved", "EQ", true)],
    rejected: [new sap.ui.model.Filter("Rejected", "EQ", true)]
};

// These are the counts that should be displayed on your filter buttons.
// Bind them from your view
var oViewModel = new JSONModel({
    approved: 0,
    rejected: 0
});
this.getView().setModel(oViewModel, "view");

// This will run the 2 read statement. One with each of the filters in 
// effect. The result will go into the oViewModel values declared above.
jQuery.each(_mFilters, function (sFilterKey, oFilter) {
    oModel.read("/Expense/$count", {
        filters: oFilter,
        success: function (oData) {
            var sPath = "/" + sFilterKey;
            oViewModel.setProperty(sPath, oData);
        }
    });
});

然后绑定Tile控件的count属性,例如:{view> matMaster}。每个瓷砖都应该显示它的相应数量。

答案 1 :(得分:0)

下面给出的代码将获取已批准或拒绝的请求数,并以平铺编号显示。

<强> tiletest.view.js

    createContent : function(oController) {
  var oDataModel = new sap.ui.model.odata.ODataModel("https://accountname/packagename/tile.xsodata", true);


var appritems,rejectitems;


oDataModel.read("/Expense/?$filter=STATUS eq 'Approved'", null, null, false,function success(oData){ appritems=oData.results.length;}, function failure(){});
oDataModel.read("/Expense/?$filter=STATUS eq 'Rejected'", null, null, false,function success(oData){ rejectitems=oData.results.length;}, function failure(){});
 var items;
var page1 = new sap.m.Page("page1", {
    content :[
 new sap.m.TileContainer({
    tiles : [ 
 new sap.m.StandardTile("tile1",{
        number: appritems,
        title : "Approved",
        info:  "Approved Requests",
        infoState : "Success",
        press : function() {
          oController.appr();
        }
    }),
    new sap.m.StandardTile("tile2",{
        number: rejectitems,
        title : "Rejected",
         info:  "Rejected Request",
         infoState : "Warning",
        press : function() {
            oController.appr1();
        }
    })

     ]

})
            ]
});
return page1;
}