Accessing multiple models in xml view with openUI5

2019-09-02 18:03发布

问题:

In my controller I'm setting my models with a name:

var oModel = new JSONModel();
oModel.setData({
    delimiterDRS1: " - ",
    dateValueDRS1: dateFrom,
    secondDateValueDRS1: dateTo,
    dateFormatDRS1: "dd/MM/yy"
});
oView.setModel(oModel, "dateRange");

and in my xml view I've tried

<Text text="{dateRange>dateValueDRS1}"></Text>
<Text text="{/dateRange/dateValueDRS1}"></Text>

and neither of those work. I've even tried to set the model globally by doing

sap.ui.getCore().setModel(oModel, "dateRange")

If I don't specify a model name in the setModel method and try to access the attributes {/dateValueDRS1} it works. I've been looking for documentation but haven't been able to find any. Any help would be appreciated.

回答1:

Try to read the property by using "{dateRange>/dateValueDRS1}". The way you read it, would work in a relative path. Check the documentation topic Binding Path.