SAPUI5-bindElement第二次不起作用 [英] SAPUI5 - bindElement doesn't work the second time

查看:240
本文介绍了SAPUI5-bindElement第二次不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我调用视图的bindElement来执行Web服务并获取数据. 如果tha路径的密钥不同,则会正确执行该调用. 事件"dataReceived"没有在同一路径的第二次触发.

I call bindElement of the view to execute the webservice and get data. The call is executed correctelly if the key of tha path is different. The event "dataReceived" didn't trigger in the second time of the same path.

示例:

  • 第一次:

我用路径"ABCD"调用bindElement,它正在工作,dataReceived被触发.

I call bindElement with the path 'ABCD', it's working, dataReceived is trigerred.

  • 第二次:

如果我将同一路径称为"ABCD",则会发生注意,事件dataReceived不会触发.

If I call the same path 'ABCD', noting is happend, the event dataReceived didn't trigger.

如果我将另一个路径称为"EFGH",则该路径正在工作,并且dataReceived被触发.

If I call another path 'EFGH', it's working and dataReceived is trigerred.

那么即使路径相同,我该怎么办用bindElement触发事件?

So what can I do to trigger the event with bindElement even if the path is the same ?

谢谢.

cb = this.getView().byId("cb").getValue();
vpath = "/ZDECL_INSet('"+ cb +"')";

this.getView().bindElement({
			path: vpath,
			mode: sap.ui.model.BindingMode.TwoWay,
			events: {
				dataReceived: function(rData) {

					var data = vthis.getView().getModel().getProperty(rData.oSource.sPath);
					msg = "";

					if(data.TMSG1 == 'E'){
						msg = data.Msg1;

						sap.m.MessageBox.show(msg, {
							icon: sap.m.MessageBox.Icon.ERROR,
							title: vtitle,
							actions: [sap.m.MessageBox.Action.YES],
							onClose: function(oAction) {

								oCB.focus();
								oCB.setValue(null);
							}
						}
						);

					}
					else{
						sap.m.MessageToast.show("Good", {
							duration: 2000,
							width: "200px"
						});

						oCB.focus();
						oCB.setValue(null);

					}

				}
			}
		});

推荐答案

仅当接收到数据时才会触发DataReceived.因此不会再次请求数据,因此不会触发dataReceived.

DataReceived will be fired only if data is received. So second time data will not be requested, so dataReceived won't be fired.

为此使用更改"事件.

作为此处涉及的三个事件的示例,按照它们被触发的顺序.

As example of the three events involved here, in the order they are fired.

events: {
    dataRequested: function(){
        //Here the code to be executed when a request to server was fired. For example, set a "waitingForData" flag to true
    },
    change: function(){
        //Here your magic to be executed everytime you do ElementBinding. For example, check if your "waitingForData" flag is false, if so, do whatever you want with the data you already have.
    },
    dataReceived: function(rData){
        //Here your logic to be executed when data from server is received. For example, set your "waitingForData" flag to false, and do whatever you want with the data have reveived.
    }
}

这篇关于SAPUI5-bindElement第二次不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆