我正在尝试在 UI5 表单输入字段中显示 edm.time 类型的 odata 属性 。 查看代码
<Input id="id1" placeholder="Enter value" value="{ path: 'START_TIME', mode: 'sap.ui.model.BindingMode.OneWay' }" width="500%" editable="false"/>
START_TIME 是实体的属性
Controller 代码-
onInit: function () {
var model= new sap.ui.model.odata.v2.ODataModel("<xsodata url>");
model.setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay);
this.getView().setModel(model);
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.getRoute("<pattern_name>").attachMatched(this._onObjectMatched, this);
},
_onObjectMatched: function (oEvent) {
var oArgs, oView;
oArgs = oEvent.getParameter("arguments");
oView = this.getView();
oView.bindElement({
path : "/" + oArgs.objPath
});
}
Here object path is as follows-
/Entityname/<id of a partcular item in that entity>
当我尝试在 View 中显示开始时间属性时,它返回对象对象。我需要字符串格式的时间。我已经在表中使用了格式化程序,它工作正常。但是有聚合items 绑定(bind)不同,因为它是一个表控件。我需要 UI5 表单中输入字段中的值 请帮忙
最佳答案
/EntitySet('id') //In case of a string id
/EntitySet(id) //In case of a number id
也不支持以双//开头。请检查是否需要"/"+
。
OData Edm.Time 可以使用 sap.ui.model.odata.type.Time
进行格式化。类型:
<Input id="id1" placeholder="Enter value" value="{ path: 'START_TIME', mode: 'sap.ui.model.BindingMode.OneWay', type: 'sap.ui.model.odata.type.Time' }" width="500%" editable="false"/>
您可以进一步提供format options自定义输出:
<Input id="id1" placeholder="Enter value" value="{ path: 'START_TIME', mode: 'sap.ui.model.BindingMode.OneWay', type: 'sap.ui.model.odata.type.Time', formatOptions: {style: 'short'} }" width="500%" editable="false"/>
类型(与格式化程序相比)支持输入和输出转换。因此它们可以用于双向绑定(bind)输入,无需额外编码。
关于javascript - 在UI5表单输入字段中显示odata时间值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39543658/