【发布时间】:2015-02-11 12:56:36
【问题描述】:
我构建了这个 JSON(测试为有效)(.. 不要介意这里的男人和女人的名字是一样的 :-)):
{
"staff": {
"berlin": [{
"male": [
{"firstName": "Lasse", "lastName": "Larsson"},
{"firstName": "Gerrit", "lastName": "Gartner"}
],
"female": [
{"firstName": "Lasse", "lastName": "Larsson"},
{"firstName": "Gerrit", "lastName": "Gartner"}
]
}],
"paris": [{
"male": [
{"firstName": "Lasse", "lastName": "Larsson"},
{"firstName": "Gerrit", "lastName": "Gartner"}
],
"female": [
{"firstName": "Lasse", "lastName": "Larsson"},
{"firstName": "Gerrit", "lastName": "Gartner"}
]
}],
"oslo": [{
"male": [
{"firstName": "Lasse", "lastName": "Larsson"},
{"firstName": "Gerrit", "lastName": "Gartner"}
],
"female": [
{"firstName": "Lasse", "lastName": "Larsson"},
{"firstName": "Gerrit", "lastName": "Gartner"}
]
}]
}
}
在我的控制器中,我将 JSON 模型设置为整个视图,如下所示:
// init instance of JSON model
this.staffData = new sap.ui.model.json.JSONModel();
// load JSON file into model
this.staffData.loadData("ajax-dummy/staff.json");
// bind model to whole view
this.getView().setModel(this.staffData);
在我的 XML 视图中,我现在想动态构建一个(嵌套的)DropdownBox 这应该让我选择例如 柏林->男性->姓氏 所以我需要 3 级 ListItems。
第一个问题是:我可以用 JS 生成这个(为每个构建一个 Listitem 键入人员对象等),但我不知道如何在 XML 视图中处理这个问题。 目前看起来是这样的:
<content>
<DropdownBox id="dd-locations" editable="true">
<core:ListItem text="{/staff/berlin}"></core:ListItem>
</DropdownBox>
</content>
它(当然)只在 den DropdownBox 中显示 "{object ..}",因为它是一个对象。
这甚至可以在带有数据绑定的 XML 视图中构建吗?或者有没有更好的结构方式 JSON?我知道 ListItems 需要一个数组...最后:如何嵌套 ListItems?有没有更好的控制 那么我应该使用 DropdownBox 吗?
编辑: 我想要的是“只是”嵌套 Listitems,就像我可以在 HTML 中一样。我试过了,例如:
<ComboBox>
<items>
<core:ListItem key="key2" text="text2"/>
<core:ListItem key="key3" text="text2">
<ComboBox>
<items>
<core:ListItem key="key4" text="text3"/>
<core:ListItem key="key5" text="text3"/>
<core:ListItem key="key6" text="text3"/>
</items>
</ComboBox>
</core:ListItem>
<core:ListItem key="key4" text="text2"/>
</items>
</ComboBox>
但是当发生错误时:
未捕获的错误:无法添加没有默认聚合的直接子级 为控件定义 sap.ui.core.ListItem
如何为 ListItem 定义项目聚合?这行得通吗?
非常感谢,呵呵
【问题讨论】:
标签: xml json data-binding sapui5