我目前正在使用 REACT 将现有的 javascript 重构为 SharePoint 框架解决方案。我得到了大部分工作,但我很难用 Render 函数来返回具有可变列数的表的 html 内容。列数是从 Web 部件属性设置的。如何将原始 javascript(如下)转换为 REACT 代码?
var html = "<table>";
for (var i = 0; i < data.d.results.length; i++) //data is from AJAX SP REST query
{
if ((i % tdWidth) == 0 ) { html += "<tr>"; } //if this is the first column in the row
html += "<td><div>" + data.d.results[i] + "</div></td>";
if ((i % tdWidth) == (tdWidth - 1) ) { html += "</tr>"; } //if this is the last column in the row
}
html += "</table>";
$("#tableContainerDiv").html(html); //Set the html tag of the container div