简体   繁体   English

SAPUI5:详细视图控制器 - 访问数据

[英]SAPUI5: Detail View Controller - Access Data

I'm stuck with my little UI5 app.我被我的小 UI5 应用程序困住了。 It's a master/detail app with the according 2 views.这是一个主/详细应用程序,具有相应的 2 个视图。 I want to get access to the selected data set inside the detail controller.我想访问详细信息控制器内的选定数据集。 The view and the app itself work.视图和应用程序本身可以工作。 I can display the data inside the detail view.我可以在详细视图中显示数据。

But I need the data in the controller.但我需要控制器中的数据。 I spent hours reading and I'm sure it must be very simple.我花了几个小时阅读,我相信它一定很简单。

Inside the detail controller in the handleRouteMatched I defined a new variable var dataObject = this.getView().bindObject(oPath);handleRouteMatched的细节控制器中,我定义了一个新变量var dataObject = this.getView().bindObject(oPath);

When I debug the dataObject I see that the data is there (but all data not just the selected).当我调试dataObject我看到数据在那里(但所有数据不仅仅是选定的数据)。 It's deep inside the "undefined"它在“未定义”的深处Chrome 调试器图片

Chrome 调试器 2 And I have no clue how to get hold of this.我不知道如何掌握这个。 Can someone help?有人可以帮忙吗?

EDIT:编辑:

var sContext = this.getView().oController.sContext; //Retrieve context
var oModel = this.getOwnerComponent().getModel(); // Aquire the model
console.log(oModel.getProperty("/" + sContext + "/Businesstravel"));

That's how I finally got it working.这就是我最终让它工作的方式。 It would have been nice to get the whole record though (not only single fields).虽然获得整个记录会很好(不仅仅是单个字段)。

  1. get the object where you have binded the context.获取绑定上下文的对象。
  2. get this context, and get the path from it.获取此上下文,并从中获取路径。
  3. get the corresponsing data from your model using the path使用路径从您的模型中获取相应的数据

something like this:像这样:

var oView = this.getView().byId('DetailPage1');
var sPath = oView.getBindingContext('myModelName').getPath();
var myData = this.getView().getModel('myModelName').getProperty(sPath);

EDIT编辑

Well I didn't follow all your code, but tested two things that will help you.好吧,我没有遵循您的所有代码,但测试了两件对您有帮助的事情。

First, to get the parameters in your route I use in your detailPage1 Controller首先,要获取路线中的参数,我在您的 detailPage1 控制器中使用

onInit: function(){
this.oRouter = sap.ui.core.UIComponent.getRouterFor(this);
this.oRouter.getRoute("DetailPage1").attachPatternMatched(this._onObjectMatched, this);
...
},

_onObjectMatched: function(oEvent) {
  var contextFromRouterParameter = oEvent.getParameter("arguments").context;
  console.log('contextFromRouterParameter: ' + contextFromRouterParameter);
},

Second, to get your model (you defined it in the manifest, so it is set in the component level) you need to do:其次,要获取您的模型(您在清单中定义它,因此它是在组件级别设置的),您需要执行以下操作:

var oModel = this.getOwnerComponent().getModel();

Wherever you wnat to retrieve it.无论您想在哪里检索它。 Then you can use its functions like: getProperty(sPath) as I mentioned before然后你可以使用它的功能,比如: getProperty(sPath)正如我之前提到的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM