我尝试了不同的SAPUI5演示应用程序,如购物车,管理产品。但是我无法解决我的问题。我有两种观点。在家庭观点我已经将我的模型设置为全球性的
var model = this.getView().getModel('product');
var oModel = new sap.ui.model.json.JSONModel(model);
sap.ui.getCore().setModel(oModel, "product");
然后我导航到产品页面。我正在访问我的产品名称并尝试访问我的特定产品以与我当前的视图绑定。
_routePatternMatched: function(oEvent) {
var name= oEvent.getParameter("arguments").name,
oView = this.getView(),
sPath = "/Product('" + sId + "')";
console.log(sPath);
var oModel = sap.ui.getCore().getModel("product");
var oData = oModel.getData(sPath);
console.log(oData);
oView.bindElement({
path: sPath,
events: {
dataRequested: function() {
oView.setBusy(true);
},
dataReceived: function() {
oView.setBusy(false);
}
}
});
//if there is no data the model has to request new data
if (!oData) {
oView.setBusyIndicatorDelay(0);
oView.getElementBinding().attachEventOnce("dataReceived", function() {
// reset to default
oView.setBusyIndicatorDelay(null);
this._checkIfCourseAvailable(sPath, name);
}.bind(this));
}
},
_checkIfCourseAvailable: function(sPath) {
var oModel = sap.ui.getCore().getModel("product");
var oData = oModel.getData(sPath);
// show not found page
if (!oData) {
this._router.getTargets().display("notFound");
}
},
我通过id过滤得到了正确的结果。现在在给var oData = oModel.getData(sPath);
console.log(oData);
路径后它有正确的结果,但我无法在视图中显示数据我正在尝试{pruduct>/name}
答案 0 :(得分:0)
在bindElement中传递模型名称,然后通过模型名称进行访问..
oView.bindElement({
path: sPath,
model:modelName,
events: {
dataRequested: function() {
oView.setBusy(true);
},
dataReceived: function() {
oView.setBusy(false);
}
}
});
在视图中使用{modelName>name}