How can I use data binding from a model in the renderer of a custom control? The m.getProperty("/time/0/hours") function returns undefined. The binding in the span,
oRm.write("{/time/0/hours}") returns the literal string, and errors if without quotes.
I have an XML view with a custom control:
<mvc:View
controllerName="view.Calendar"
xmlns:mvc="sap.ui.core.mvc"
xmlns:c="control"
xmlns="sap.m">
<c:TimeCalendar
id="calIdView"
hoursData="data.json" />
</mvc:View>
The controller:
sap.ui.controller("view.Calendar", {
onInit: function(oEvent){
jQuery.sap.includeStyleSheet("main.css");
var oModel = new sap.ui.model.json.JSONModel("data.json");
this.getView().setModel(oModel, "hours");
}
});
And my custom control:
sap.ui.unified.Calendar.extend("control.TimeCalendar", {
metadata : {
properties : {
"hoursData" : "string"
}
},
// the part creating the HTML:
renderer:{
renderDays: function(oRm, oCal, oDate){
if (!oDate) {
oDate = oCal._getFocusedDate();
}
var sHoursData = oCal.getHoursData();
var oModel = new sap.ui.model.json.JSONModel(sHoursData);
oCal.setModel(oModel);
var m = oCal.getModel("hours");
console.log(m.getProperty("/time/0/hours"));
...
oRm.write("<span class=\"hours\">");
oRm.write("{/time/0/hours}");
oRm.write("</span>");