我有这门课
public class Cluster {
private int clusterId = -1;
private DataPoint centroid;
private ArrayList<DataPoint> points;
private boolean selected = false;
private float clusterPercentage = -1;
private int clusterValue = -1;
public Cluster(int id, DataPoint centroid) {
...
}
}
在我的聚类算法完成后,它会创建几个簇,这些簇存储在 ArrayList
中,如下所示:
ArrayList<Cluster> my_clusters;
my_clusters.add(new Cluster(...));
所有集群都有一些 clusterPercentage
和 clusterValue
值
我正在使这个互动。因此,我设置了一个 Tomcat Server 8
并在 .jsp
我不想做的是能够打印出每个集群计算出的数据,并基于此允许用户更改每个集群的selected
变量。
为此,我迭代 Cluster ArrayList 并打印它。
for (int i = 0; i < km.k; ++i) {
%>
<div class="col-md-4">
<div class="thumbnail">
<div class="caption">
<p><strong>Cluster</strong> <%=cluster_id %>: <%=cluster_size%> points. <br>
Percentage: <%=df4.format(cluster_percentage)%> % <br>
Expressed value: <%=cluster_value %> <br>
Filter test: <%
if (cluster_filter) {
%><strong>PASS</strong><%
}
else {
%>FAIL<%
}
%><br><hr>
Sample: <%=sample_id%><br>
Value: <%=sample_highest_value%><br>
Expr. percentage:
<%
if (sample_highscore >= threshold) {
%><strong><%=df4.format(sample_highscore)%> %</strong><%
}
else {
%><%=df4.format(sample_highscore)%> %<%
}
%>
<div class="checkbox">
<label><input type="checkbox" value="">Option 1</label>
</div>
</div>
</div>
</div>
<%
} %>
所以我的问题是:
有没有办法动态地将 id 分配给我的 checkbox div
以便我能够知道选择了哪个复选框?当然,div
必须与 clusterId
匹配。
最佳答案
您可以使用相同的 cluster_id 为 div 创建动态 ID。
<div class="checkbox" id="<%=cluster_id %>_div">
关于java - 动态分配 id 给 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42023581/