OData .create 请求后的成功回调



我正在使用OData v2模型创建简单的SAP Fiori应用程序。我已经完成了 .create(...) 请求的实现,它可以在后端系统上工作,但我在成功回调函数方面遇到了问题。

创建新对象后,我想显示消息吐司及其编号并返回上一个视图。

如何在成功/错误 (_onBatchError) 回调中使用_createNotification函数中的对象?

_createNotification: function() {
  var oModel = this.getModel();
  var that = this; 
  // ....
  oModel.create("/NotificationHeaderSet", oNotification, {
				
    success: function(oData, oResponse) {
	  MessageToast.show(oData.NotificationNo);  // How to get i18n ?
      // this.getRouter().navTo("worklist", {}, true);
	},
    error: this._onBatchError
  });
}

this, that, oModel未定义,sap.ui.core.getCore().getModel()给出 null(在此回调默认值之外/i18n 模型处理正常)

可能是一些虚拟错误,但我没有想法。

提前非常感谢。雅各布

使用 jQuery.proxy 它应该可以工作:

_createNotification: function() {
  var oModel = this.getModel();
  var that = this; 
  // ....
  oModel.create("/NotificationHeaderSet", oNotification, {
				
    success: jQuery.proxy(function(oData, oResponse) {
	  MessageToast.show(oData.NotificationNo);  // How to get i18n ?
      this.getRouter().navTo("worklist", {}, true);
	}, this),
    error: this._onBatchError
  });
}

最新更新