Hi Guru's,
I am doing some trainings in SAPUI5 and also bought the great SAP Press book "SAPUI5 The comprehensive guide". Especially in this book I run into an example where they use a metadataLoaded function on the model when binding data to a view. If I understood it correctly then this function fires when the metadata on the model was loaded so that you know you can access the metadata.
The book uses something like the code example below:
var sSalesOrderID = oEvent.getParameter("arguments").BusinessPartnerID;
oModel.metadataLoaded().then(function() {
var sObjectPath = this.getView().getModel().createKey("SalesOrderSet", {
SalesOrderID: sSalesOrderID
});
this.getView().bindElement({
path: "/" + sObjectPath
})
}.bind(this));
The sObjectPath variable then contains a value like "SalesOrderSet('0500000002')", this works perfectly but I want to understand why I have to use this metadataLoaded method because before I bought the book I followed some openSAP trainings and followed the tutorials on the SAPUI5 website and there I learned to do the same through:
var sSalesOrderID = oEvent.getParameter("arguments").BusinessPartnerID;
this.getView().bindElement({
path: "/SalesOrderSet('" + sSalesOrderID + "')"
});
Both code samples above work perfectly so the main question I have is: what does the metadataLoaded exactly do and in which situations should you use it (or should you always use it)?
Kind Regards,
Nico van der Linden