I have a problem binding my JSON Model to a sap.m.table
. The model itself gets generated through an array which itself gets filled throughout the code and in the end it consists of different objects.
Here's a screenshot of the object data:
That structure seems kind of weird to me since I always have to click the (...) in order to see the actual content.
Anyhow, I try to bind the labelName and uploadName to a two-column-table.
<m:Table id="emptyColumnText" rows="{/emptyColModel}">
<m:headerToolbar>
<m:Toolbar height="2rem">
<m:Title text="{i18n>excel.emptyColMessage}" />
</m:Toolbar>
</m:headerToolbar>
<m:columns>
<m:Column>
<m:Text text="Excel Upload" />
</m:Column>
<m:Column>
<m:Text text="InfoObject" />
</m:Column>
</m:columns>
<items>
<ColumnListItem>
<cells>
<Text text="{/uploadName}" /> //different approaches to
<Text text="{>labelName}" /> // see what works
</cells>
</ColumnListItem>
</items>
</m:Table>
I already tried different approaches in binding the Model to the table items and also binding the upload-/labelName to the cells, but I haven't been successful yet. Also I'd like to do all of my binding in the view, not in the controller!
Here's how I set my model:
var emptyColMessage = new sap.ui.model.json.JSONModel(emptyCol, 'emptyColModel');
dialog.setModel(emptyColMessage); // a new dialog opens which should contain the model, so I thought I'd set the model to the dialog
and this is how emptyCol looks with one entry:
Looking at the UI5 Inspector. I see, that the table has a binding to the /emptyColModel but there are no items listed or anything that points to a correct binding.
So how do I correctly bind my data? I tried several attempts of how I add the path.
Edit
I just looked at the model information an realized that the mmodel data looks like that:
So I guess, accessing uploadName gets kind of hard when it's not an actual property of the model but only a string?
Edit 2
Update regarding @TiiJ7 's help
if (emptyCol.length !== 0) {
var emptyColMessage = new sap.ui.model.json.JSONModel({ emptyColModel: emptyCol });
// var emptyColMessage = new sap.ui.model.json.JSONModel(emptyCol, 'emptyColModel');
}
if (randomMatch.length !== 0) {
var randomMatchMessage = new sap.ui.model.json.JSONModel({ randomColModel: randomMatch });
}
if (matchedColumn.length !== 0) {
var matchedColumnMessage = new sap.ui.model.json.JSONModel({ matchedColModel: matchedColumn });
}
dialog.setModel(emptyColMessage, 'emptyColModel');
dialog.setModel(randomMatchMessage, 'randomColModel');
dialog.setModel(matchedColumnMessage, 'matchedColModel');
my xml code for the first table:
<m:Table id="emptyColumnText" items="{/emptyColModel}">
<m:headerToolbar>
<m:Toolbar height="2rem">
<m:Title text="{i18n>excel.emptyColMessage}" />
</m:Toolbar>
</m:headerToolbar>
<m:columns>
<m:Column>
<m:Text text="Excel Upload" />
</m:Column>
<m:Column>
<m:Text text="InfoObject" />
</m:Column>
</m:columns>
<m:items>
<m:ColumnListItem>
<m:cells>
<m:Text text="{/emptyColModel>labelName}" /> //I again tried different solutions
<m:Text text="{uploadName}" />
</m:cells>
</m:ColumnListItem>
</m:items>
</m:Table>