对单个OData实体的bindProperty [英] bindProperty to Single OData Entity

查看:47
本文介绍了对单个OData实体的bindProperty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在UI5中,如果您的模型是OData,是否可以将单个实体的单个属性绑定到控件属性?如果将聚合绑定到实体集,则绑定可以正常工作,但似乎无法将属性与实体一起使用.假设我有一个名为TestSet的实体集.每个测试"都有属性KeyName.我想将表的标题绑定到该集合上实体之一的Name.

In UI5, is it possible to bind a single attribute of a single entity to a control property if your model is an OData? Binding works ok if you bind an aggregation to an entity set but does not seem to work with properties to entities. Say I have an entity set called TestSet. Each "Test" has attribute Key and Name. I'd like to bind the title of a table to the Name of one of the entities on that set.

以下代码有什么问题?

createContent: function(oController) {
    jQuery.sap.require("sap.ui.table.Table");
    var oTable = new sap.ui.table.Table({title: "{/TestSet('01')/Name}"});
    oTable.setModel(new sap.ui.model.odata.ODataModel("/path/to/root/of/odata/"));
    oTable.bindProperty("title", "/TestSet('01')/Name");
    return oTable;
},

在单独测试时,OData可以正常工作. /TestSet返回一组Test实体,/TestSet('01')返回其中一个实体.

OData works ok when tested in isolation. /TestSet returns set of Test entities and /TestSet('01') returns one of those entities.

我已经测试了对/Name/TestSet('01')/Name等的绑定.似乎没有任何作用.

I've tested binding to /Name, /TestSet('01')/Name, etc. Nothing seems to work.

推荐答案

您可以通过将控件绑定到特定元素(实际上,层次结构是aggregation-> element-> property)来实现这样的属性绑定.因此,以您的示例为例,您可以这样做:

You can effect a property binding like this by binding the control to the specific element (hierarchy, as it were, is aggregation->element->property). So taking your example, you could do this:

var oTable = new sap.ui.table.Table({
  title : "{Name}"
});

,然后执行此操作:

oTable.bindElement("/Products(0)");

HTTP调用是由OData模型机制进行的,并且该值显示在表的title属性中.

the HTTP call is made by the OData model mechanism and the value appears in the table's title property.

这是一个使用Northwind的正在运行的示例.

这篇关于对单个OData实体的bindProperty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆