是否可以将两个模型绑定到一个控件?

时间:2018-03-29 11:02:21

标签: sapui5

我需要在StandardTile中显示两个数字。数据源是一个SOAP Web服务,我必须使用不同的参数调用两次才能获得这两个数字。有没有办法用这两个数字填充瓷砖?我尝试为每个ajax调用Web服务创建一个XMLModel,然后将控件的属性绑定到响应中的节点,但我只是重复相同的数字。

下面是我在控制器中的onInit方法

onInit: function () {
        // callback from ajax request
        SOAPRequester.getMessageOverview(function (data) {
            var oModel = new sap.ui.model.xml.XMLModel();
            oModel.setData(data);
            var oStandardTile = sap.ui.getCore().byId("__xmlview0--messageOverviewTile");
            if (oStandardTile !== undefined) {
                oStandardTile.setModel(oModel, "overview");
                oStandardTile.bindProperty("number", {
                    path: "/SOAP-ENV:Body/rpl:getMessageListResponse/Response/rn5:number",
                    model: "overview"
                });
            }
        });
        //callback from the second ajax call
        SOAPRequester.getErrorMessages(function (callbackData) {
            var oModel = new sap.ui.model.xml.XMLModel();
            oModel.setData(callbackData);
            var oStandardTile = sap.ui.getCore().byId("__xmlview0--messageOverviewTile");
            if (oStandardTile !== undefined) {
                oStandardTile.setModel(oModel, "overview");
                oStandardTile.bindProperty("infoState", "Error");
                oStandardTile.bindProperty("info", {
                    path: "/SOAP-ENV:Body/rpl:getMessageListResponse/Response/rn5:number",
                    model: "overview"
                });
            }
        });


    },

1 个答案:

答案 0 :(得分:2)

是的,确实如此。您使用相同的型号名称两次,因此第一次不再可见。只需使用不同的型号名称,即“概述”和“概述2”或您喜欢的内容:

this.map.addListener('click', (event) => {
    this.zone.run(() => {
      this.addMarker(event.latLng);
    });
  });

提示:您还可以稍微改进一下代码,即

  • 致电onInit: function () { // callback from ajax request SOAPRequester.getMessageOverview(function (data) { var oModel = new sap.ui.model.xml.XMLModel(); oModel.setData(data); var oStandardTile = sap.ui.getCore().byId("__xmlview0--messageOverviewTile"); if (oStandardTile !== undefined) { oStandardTile.setModel(oModel, "overview"); oStandardTile.bindProperty("number", { path: "/SOAP-ENV:Body/rpl:getMessageListResponse/Response/rn5:number", model: "overview" }); } }); //callback from the second ajax call SOAPRequester.getErrorMessages(function (callbackData) { var oModel = new sap.ui.model.xml.XMLModel(); oModel.setData(callbackData); var oStandardTile = sap.ui.getCore().byId("__xmlview0--messageOverviewTile"); if (oStandardTile !== undefined) { oStandardTile.setModel(oModel, "overview2"); oStandardTile.bindProperty("infoState", "Error"); oStandardTile.bindProperty("info", { path: "/SOAP-ENV:Body/rpl:getMessageListResponse/Response/rn5:number", model: "overview2" }); } }); }, 或者如果您拥有正确的UI5版本this.getView().byId("messageOverviewTile")而非this.byId("messageOverviewTile")

  • 在视图中对您的控件进行绑定,然后在sap.ui.getCore().byId("__xmlview0--messageOverviewTile")调用onInit()this.getView().setModel(oModel, "overview")