我在JS视图中构建SAPUI5应用程序我有一个JSON模型如下
{
"Categories": [
{
"name":"L1 Category One",
"icon":"sap-icon://home",
"description":"Sample Description",
"sub-categories":{[
{
"name":"L2 Category One",
"icon":"sap-icon://action",
"description":"Sample Description",
}
]}
}
{
"name":"L1 Category Two",
"icon":"sap-icon://action",
"description":"Sample Description"
}
{
"name":"L1 Category Three",
"icon":"sap-icon://doctor",
"description":"Sample Description"
}
{
"name":"L1 Category Four",
"icon":"sap-icon://cart",
"description":"Sample Description"
}
]
}
我使用此模型构建类似于类别导航的图块,如下所示
var oSampleLayout = new sap.ui.layout.HorizontalLayout("cats-layout");
oSampleLayout.setModel(oModel);
var ooCategoryIcon = new sap.ui.core.Icon();
ooCategoryIcon.setSrc("{icon}");
ooCategoryIcon.addStyleClass("category-icon");
var ooCategoryName = new sap.ui.commons.TextView();
ooCategoryName.setText("{name}");
var oOtherTemplate = new sap.ui.commons.layout.VerticalLayout("",{content:[ooCategoryIcon,ooCategoryName]});
oOtherTemplate.addStyleClass("cat");
oOtherTemplate.attachBrowserEvent('click',soidPress);
oSampleLayout.bindAggregation("content",{path:"/Categories",template:oOtherTemplate});
oSampleLayout.placeAt('other-content');
点击我获取绑定上下文并调用一个方法来渲染子类别,我将上下文传递给渲染方法,但是我被困在获得子类别渲染我怎么能去做?任何想法
答案 0 :(得分:0)
我已将context.oModel设置为子类别的模型,并使用上下文路径绑定元素
oxLayout.bindElement(oContext.sPath);
这允许我绑定来自上下文路径的特定元素,并再次使用聚合形成子类别。