我试图将数据绑定到服务中的下拉列表(sap.m.Select
)中,但下拉列表中未显示数据。下面是我的代码:
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel"
], function (Controller, JSONModel) {
"use strict";
return Controller.extend("hmel.TravelandGuestHouse.controller.CloneTravelRequest", {
onInit: function () {
this.router = sap.ui.core.UIComponent.getRouterFor(this);
//For Train Name
this.addmodel = new JSONModel();
this.getView().setModel(this.addmodel, "Model");
this.actionTemp = this.getView().byId("trainName").clone();
this.detailModel = sap.ui.getCore().getModel("detailModel");
this.getView().setModel(this.detailModel, "detailModel");
this.router.attachRoutePatternMatched(this._handleRouteMatched, this);
},
_handleRouteMatched: function(evt) {
if (evt.getParameter("name") !== "CloneTravelRequest") {
return;
}
var that = this;
that.getView().byId("trainName").bindAggregation("items", {
path: "/TravelPrpTrainDetails",
template: that.actionTemp
});
}
});
});
<m:Select id="trainName" selectedKey="{detailModel>/TrainName}">
<core:Item key="{ID}" text="{TrainName}"/>
</m:Select>
数据以下面的形式出现,我只想从中提取TrainName
属性:
<entry>
<id>http://________________________/TravelPrpTrainDetails(36)</id>
<category
term="WCFODataService.TravelPropTrainDetails"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
/>
<link
rel="edit"
title="TravelPropTrainDetails"
href="TravelPrpTrainDetails(36)"
/>
<title />
<updated>2019-01-03T06:02:36Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:SerialNo m:type="Edm.Int32">2</d:SerialNo>
<d:ID m:type="Edm.Int32">36</d:ID>
<d:TrainName>AJMER ASR EXPRESS 19611</d:TrainName>
</m:properties>
</content>
</entry>
答案 0 :(得分:0)
嗨,Swappy,解决方案非常简单。您项目的绑定应使用与父绑定相同的模型名称。在这种情况下,您应该具有:
<core:Item key="{detailModel>Value}" text="{detailModel>Value}"/>
通常,当模型不是默认模型时(默认是没有名称的模型),应始终使用此规则。
<ComboBox
items="{ModelName>/ListOfValues}">
<core:Item key="{ModelName>Key}" text="{ModelName>Value}"/>
</ComboBox>
如果您使用默认模型,则应使用这种模板:
<ComboBox
items="{/ListOfValues}">
<core:Item key="{Key}" text="{Value}"/>
</ComboBox>