Path SAPUI5-bindElement不';我第二次不工作了

Path SAPUI5-bindElement不';我第二次不工作了,path,sapui5,Path,Sapui5,我调用视图的bindElement来执行webservice并获取数据。 如果路径的键不同,则正确执行调用。 事件“dataReceived”未在同一路径的第二次触发 例如: 第一次: 我用路径'ABCD'调用bindElement,它正在工作,dataReceived被触发 第二次: 如果我调用相同的路径'ABCD',没有发生任何事件,则接收到的事件数据不会触发 如果我调用另一个路径“EFGH”,它会工作,并且会触发dataReceived 那么,即使路径相同,如何使用bindElem

我调用视图的bindElement来执行webservice并获取数据。 如果路径的键不同,则正确执行调用。 事件“dataReceived”未在同一路径的第二次触发

例如:

  • 第一次:
我用路径'ABCD'调用bindElement,它正在工作,dataReceived被触发

  • 第二次:
如果我调用相同的路径'ABCD',没有发生任何事件,则接收到的事件数据不会触发

如果我调用另一个路径“EFGH”,它会工作,并且会触发dataReceived

那么,即使路径相同,如何使用bindElement触发事件呢

谢谢

cb=this.getView().byId(“cb”).getValue();
vpath=“/ZDECL_INSet(“+cb+”)”;
此.getView().bindElement({
路径:vpath,
模式:sap.ui.model.BindingMode.TwoWay,
活动:{
接收到的数据:函数(rData){
var data=vthis.getView().getModel().getProperty(rData.oSource.sPath);
msg=“”;
如果(data.TMSG1=='E'){
msg=data.Msg1;
sap.m.MessageBox.show(msg{
图标:sap.m.MessageBox.icon.ERROR,
标题:vtitle,
操作:[sap.m.MessageBox.Action.YES],
onClose:函数(OAAction){
oCB.focus();
oCB.setValue(空);
}
}
);
}
否则{
sap.m.MessageToast.show(“好”{
期限:2000年,
宽度:“200px”
});
oCB.focus();
oCB.setValue(空);
}
}
}

});
如果使用相同的路径调用
bindElement
两次,第二次调用实际上不会触发新调用以获取新数据,因为路径没有更改。因为不会有第二次呼叫,所以不会有第二次
dataReceived
事件

如果您想再次触发它,可以手动触发它

this.getView().getElementBinding().fireDataReceived()


根据您的代码,当您收到响应时,您似乎正在尝试从服务器执行代码。我将使用EventProvider类中的
attachEventOnce
方法

oModel.attachEventOnce("requestCompleted", function(oEvent) {
    //execute your code here
}, this);
this.getView().bindElement(sPath);

requestCompleted事件将在数据返回一次后触发,然后清除再次发生的事件,这样您就不会总是通过相同的回调函数运行来自每个请求的每个响应。

仅当接收到数据时才会触发DataReceived。所以不会请求第二次数据,所以不会触发dataReceived

为此使用“更改”事件

作为这里涉及的三个事件的例子,按照它们被触发的顺序

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.
    }
}

DataReveived事件是通过“this.getView().getElementBinding().fireDataReceived()”触发的,但backoffice未执行。根据您的代码,当您从服务器收到响应时,您似乎正在尝试执行函数。我认为比
dataReceived
事件更好的方法是
attachEventOnce
。我在上面编辑了我的答案。请尝试一下,让我知道。我在路径中添加了一个timestanp以具有唯一的路径。但是我的
bindElement
仅激发
change
dataRequested
dataReceived
未被调用,您知道为什么吗?
dataRequested
在没有请求新数据的情况下不会被激发。因此,如果您的浏览器中有来自previos请求的数据,模型将不会再次调用服务器,并且只会触发
change
。当然,如果以前没有激发
datarequest
,则不会激发
dataReceived