我在多模型绑定(bind)方面遇到问题。
在 Controller 的 init 函数中,我在 ui.core 中设置 JSON 模型
var oModel = new sap.ui.model.json.JSONModel(data1);
sap.ui.getCore().setModel(oModel, "model1");
在 View 中,我有一个 ColumnListItem 模板,并将其绑定(bind)在表中
var template = new sap.m.ColumnListItem({
id: "first_template",
type: "Navigation",
type : sap.m.ListType.Active,
visible: true,
selected: true,
cells: [ new sap.m.Label({
text: "{name}"
})
],
press: [oController.pressListMethod]
});
oTable.bindItems("model1>/events", template, null, null);
oPage.addContent(oTable);
对于简单模型,它的工作原理是正确的,但在多模型表中只能获取项目数,但不能获取模型的属性。有什么解决办法吗?
最佳答案
您还需要在模板中使用模型名称:
var template = new sap.m.ColumnListItem({
id: "first_template",
type: "Navigation",
type : sap.m.ListType.Active,
visible: true,
selected: true,
cells: [
new sap.m.Label({
text: "{model1>name}" // No leading "/" here since the binding is relative to the aggregation binding below
})
],
press: oController.pressListMethod
});
oTable.bindItems("model1>/events", template);
oPage.addContent(oTable);
关于model-binding - SAPUI5 多模型绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27166691/