Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
572 views
in Technique[技术] by (71.8m points)

sapui5 - bindProperty to Single OData Entity

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.

What's wrong with the following code?

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 works ok when tested in isolation. /TestSet returns set of Test entities and /TestSet('01') returns one of those entities.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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}"
});

and then when you do this:

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

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

Here's a running example, using Northwind.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...