我有这个班级
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>
<%
} %>
所以我的问题是:
有没有办法动态地为我的checkbox divs
分配ID,以便我能够知道选择了哪个复选框?当然,div's
必须与clusterId
匹配。
答案 0 :(得分:2)
您可以使用相同的 cluster_id 为div创建动态ID。
<div class="checkbox" id="<%=cluster_id %>_div">
答案 1 :(得分:0)
你可以输入迭代器号来计算复选框的数量并用id附加它(如果是id)。
public class MyCheckBoxCell extends TreeCell<String> {
private final CheckBox checkBox = new CheckBox();
private BooleanProperty currentSelectedBinding ;
// only need this if you are using the indeterminateProperty() of your
// CheckBoxTreeItems
private BooleanProperty currentIndeterminateBinding ;
public MyCheckBoxCell() {
// add extra event handling to the check box here...
}
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
setText(item);
setGraphic(checkBox);
if (currentSelectedBinding != null) {
checkBox.selectedProperty().unbindBidirectional(currentSelectedBinding);
}
if (currentIndeterminateBinding != null) {
checkBox.indeterminateProperty().unbindBidirectional(currentIndeterminateBinding);
}
if (getTreeItem() instanceof CheckBoxTreeItem) {
CheckBoxTreeItem cbti = (CheckBoxTreeItem<?>) getTreeItem();
currentSelectedBinding = cbti.selectedProperty();
checkBox.selectedProperty().bindBidirectional(currentSelectedBinding);
currentIndeterminateBinding = cbti.indeterminateProperty();
checkBox.indeterminateProperty().bindBidirectional(currentIndeterminateBinding);
}
}
}
}
我希望它可以帮助你