我有一个html模板,我在牵线木偶视图中使用。当我在render函数中调用它时,我在模板中传递一个参数。我想根据参数的值添加多个div元素。如何在html模板中添加for循环?
<div id="mainArea">
<div data-role="view">
<div id="scrollView" data-role="scrollView" data-stretch="true">
<div id = 'leftArrowImage' class="leftArrowImage">
</div>
<div id = 'mainViewArea'></div>
<div id = 'rightArrowImage'></div>
/* I have passed a variable here named allWidgets. I want to add the number of divs(<div data-role="page" ></div>) equal to the length of allWidgets array. How do I do that*/
</div>
</div>
</div>
&#13;
答案 0 :(得分:1)
<link rel="stylesheet" type="text/css" href="Widgets/ReportWidget/styles/scrollLayout.css"/>
<div id="mainArea">
<div data-role="view">
<div id="scrollView" data-role="scrollView" data-stretch="true">
<div id = 'leftArrowImage' class="leftArrowImage">
</div>
<div id = 'mainViewArea'></div>
<div id = 'rightArrowImage'></div>
<% var i;
for i in allWidgets{ %>
<div data-role="page" class="pages" >
</div>
}%>
</div>
</div>
</div>
答案 1 :(得分:1)
如果您使用的是Angular,请使用*ngFor
,其中w
现在是allWidgets
数组中的每个元素,并将为每个元素创建一个div
。您可能需要围绕[data-role]
进行绑定。
<div *ngFor="let w of allWidgets">
<div data-role="page"></div>
</div>
答案 2 :(得分:0)
如果你在谈论(我不确定是否完全理解这个问题),你能尝试一下吗?
<div id="mainArea">
<div data-role="view">
<div id="scrollView" data-role="scrollView" data-stretch="true">
<div id = 'leftArrowImage' class="leftArrowImage">
</div>
<div id = 'mainViewArea'></div>
<div id = 'rightArrowImage'></div>
<c:forEach var="widget" items="${allWidgets}">
// Here, you can add parameters about widget objects in allWidgets
<div data-role="page" ></div>
</c:forEach>
</div>
</div>
</div>
您还必须在代码
下面定义jsp文件的顶部<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>