【问题标题】:UI5 XML View vs JSON View Grouped ListUI5 XML 视图与 JSON 视图分组列表
【发布时间】:2015-11-20 11:42:22
【问题描述】:

我们在 sapUI5 探索的演示中使用 openUI5 中的 JSON 视图,他们使用此 xml 视图作为分组列表

<mvc:View
controllerName="sap.m.sample.ListGrouping.List"
xmlns:l="sap.ui.layout"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m">
<List
    items="{
        path: '/ProductCollection',
        sorter: {
            path: 'SupplierName',
            descending: false,
            group: true
        },
        groupHeaderFactory: '.getGroupHeader'
    }"
    headerText="Products" >
    <StandardListItem
        title="{Name}"
        description="{ProductId}"
        icon="{ProductPicUrl}"
        iconDensityAware="false"
        iconInset="false" />
</List>
</mvc:View>

我们将它翻译成这个 json 视图,但是排序器和标头工厂被忽略了。项目按预期显示

{
   "Type": "sap.ui.core.mvc.JSONView",
   "controllerName": "company.controller.XY",
   "content": [
       {
           "Type" : "sap.m.List",
           "height" : "100%",       
           "items" : {
               "path" : "/ProductCollection", 
               "sorter" : {
                   "path" : "SupplierName",
                   "descending" : false,
                   "group" : true
               },
               "groupHeaderFactory" : ".getGroupHeader",        
               "template" : {
                   "Type" : "sap.m.StandardListItem",
                   "title" : "{Name}",
                   "description"  : "{ProductId}",
                   "icon" : "{ProductPicUrl}",
                   "iconDensityAware" : false,
                   "iconInset" : false
               }
           }
       }
   ]
}

如何将 xml 视图转换为 json 视图? 是否有任何工具可以自动执行此操作?

【问题讨论】:

  • 控制器名称:company.controller.XY - 嗯?你知道我相信这里的惯例吗?
  • 我很确定控制器没有命名为XY。除此之外,命名空间方案对我来说似乎很好。我们使用de.companyname.productname.controller.XY
  • @Bernard 我知道这一点,但我不得不掩盖公司 + 控制器名称
  • 您是否已经为您的分拣机尝试过这个:"sorter" : new sap.ui.model.Sorter("SupplierName", false,true); 这是它的 API 文档sap.ui.model.Sorter
  • @Christoph 感谢您的建议,但不幸的是您不能直接在 JSON/XML 视图中使用构造函数

标签: json xml sapui5


【解决方案1】:

我刚刚在 github 上报告了您的问题。
根据 SAP 开发人员的说法,这是recognized JSON-View Bug

...JSONView 当前无法正确解析控制器方法。这是 JSONView 中的一个已知差距,尽管早在 6 月份就已经检测到它,但遗憾的是仍未关闭(JSONViews 并没有被太多使用......)。

您唯一的选择是通过 Javascript 在控制器中创建 sap.m.List.items-Binding 或将您的视图声明切换为 Javascript 或 XML 视图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-03
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 2020-03-29
    相关资源
    最近更新 更多