这是我的代码。我只想根据所选类别显示子类别。 但它只是改变了第一行。
public void refreshSubCategoryHandle(ActionEvent E) throws Exception {
this.listSubCategories.getItems().clear();
ObservableList<SubCategory> olsc = FXCollections.observableArrayList();
olsc.clear();
Connection con = (Connection) ConnectionClass.getConnection();
String Sql = new String();
Sql = "SELECT * FROM subCategory WHERE catId = '"+listCategories.getSelectionModel().getSelectedItem().getCatId()+"'";
Statement st = (Statement) con.createStatement();
ResultSet rst = st.executeQuery(Sql);
while(rst.next()) {
System.out.println("SubCateGory : "+rst.getString("sCatName"));
olsc.add(new SubCategory(rst.getInt("sCatId"), rst.getInt("catId") , rst.getString("sCatName"), rst.getString("sCatDescription"), rst.getInt("sCatRank"), rst.getString("sCatCreatedAt"), rst.getString("sCatUpdatedAt"), rst.getString("sCatAddedBy")));
//SubCategoryList.add(ct);
}
// System.out.println(olsc.get(1));
// observableSubCategories.addAll(SubCategoryList);
this.listSubCategories.getItems().addAll(olsc);
}
每次触发此功能时,它只应在列表视图中显示类别为1的子类别,但它也会显示其他列表的数据...(旧数据)
问题:它不会替换整个旧数据,而只会替换列表视图中的1行旧数据。