javascript - 如何在 SAPUI5 的 Xml View 中编写无限行重复器

标签 javascript xml sapui5

我正在尝试在 SAPUI5 中显示复杂的 json 数据。

这是我的复杂数据:

results:{
         "name" : "sample",
         "child" : [
                    "name" : "sample",
                    "child" : [
                        "name" : "sample",
                        "child" : [
                                    "name" : "sample",
                                    "child" : [

                                     ]
                                  ]
                     ]
                 ]
        }

在这里,内在的 child 是无限的。这些取决于我的数据。

所以我的问题是如何在 xml View 中显示这种类型的数据。

之前我使用行重复器显示此类数据。那里的数据只有 3 个级别。但现在它已经无限了。那么我如何使用行重复器来显示这种类型的数据。

这是我的 3 级行中继器。

<c:RowRepeater rows="{path: bindingpath}" id="rowRepeater" >
      <c:RowRepeater rows="{path: bindingpath/somePath}" >
            <c:RowRepeater rows="{path: bindingpath/somePath/anotherpath}">

            </c:RowRepeater>
      </c:RowRepeater>
</c:RowRepeater>

最佳答案

这是一个非常有趣的问题,但我认为 rowRepeater 不会帮助您解决这个问题。

如果要绑定(bind) rowRepeater 控件的 row 属性,则应传递一个数组,其中数组中的每个位置都将是输出中的一行。

在您的结果对象中,您只有一个“根节点”。如果您有两个或更多节点,rowRepeater 将呈现您的输出。此外,绑定(bind)路径只能保存一个值,因此如果您考虑动态更改它,它将不适用于模型中的所有级别的数据。

请参阅下面的示例:

<!DOCTYPE html>
<html>
<head>

  <script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" id="sap-ui-bootstrap" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-libs="sap.ui.commons"></script>
  
  <meta charset="utf-8">
  <title>JS Bin</title>
  
  
  <script>


 // create the row repeater control
		var oRowRepeater = new sap.ui.commons.RowRepeater("rr1");
		oRowRepeater.setNoData(new sap.ui.commons.TextView({text: "Sorry, no data available!"}));
    
   
        //var dataObject = {data: ["a","b"]};
        var dataObject = { data: [
          { name: "A",
          children: [
                     {name: "A1",
                      children: [
                          {name: "A1a"}
                          ]
                      },
                     {name: "A2"}
                     ]
          },
          {name: "B"} // try to remove this line... the rowRepeater won't be rendered as there will be one position
          
        ]};
    
    
		// create JSON model
		var oModel = new sap.ui.model.json.JSONModel(dataObject);
		sap.ui.getCore().setModel(oModel);


		//create title
		var oTitle = new sap.ui.core.Title({text:"Letters"});

        oRowRepeater.setTitle(oTitle);

		//configure the RowRepeater
		oRowRepeater.setDesign("Standard");
//		oRowRepeater.setNumberOfRows(5);
//		oRowRepeater.setCurrentPage(1);
		oRowRepeater.setTitle(oTitle);


        var oRowTemplate = new sap.ui.commons.TextView({
          text: "{name}",
        });
    


		oRowRepeater.bindRows("/data", oRowTemplate);

		oRowRepeater.placeAt("content");
  </script>
</head>
  
  
<body class="sapUiBody" role="application">
  <div id="content"></div>
</body>

</html>

您需要的更多与Element binding相关比Aggregation binding .

因此,如果您的模型有很多级别,我建议使用类似 Tree 的控件或TreeTable .

关于javascript - 如何在 SAPUI5 的 Xml View 中编写无限行重复器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29855088/

相关文章:

javascript - ng-repeat 基于下拉选择或搜索输入

javascript - 在 Javascript 中实现 GroupBy 最有效的方法是什么?

python - 使用 Python 3.2 从头开始​​创建 Unicode XML

javascript - 销毁Xml View sapui5

javascript - 将 jQuery 转换为用户脚本的纯 Javascript 时遇到问题

javascript - 检查对象是否是JS中的事件

c# - 帮助使用 Linq 查询 XML

python - 在其他字段发生变化时更改字段值 OpenERP/Python

javascript - SAPUI5 文件 uploader : Cannot find and append file to FormData()

sapui5 - 导航到不同的 (JS) View - 无法访问路由器