/**
* 根据类型获取递归分类
*/
public void classByType() {
StringBuilder allClass = new StringBuilder();
List<CopyingCar> cars = CopyingCar.dao.getAllByTypeAndTag(getParaToInt("type"),getPara("tag"));
if(cars != null) {
for(CopyingCar car:cars) {
StringBuilder oneClass = new StringBuilder();
allClass.append("<option value='");
allClass.append(car.getId());
allClass.append("'>|--");
allClass.append(car.getName());
allClass.append("</option>");
allClass.append(getChildClass(oneClass, car.getId(),1));
}
}
setAttr("list", allClass.toString());
renderJson();
}
/**
* 获取下级分类
* @return
*/
private StringBuilder getChildClass(StringBuilder oneClass,int id,int num) {
num++;
List<CopyingCar> cars = CopyingCar.dao.getChildById(id);
if(cars != null && cars.size() > 0) {
for(CopyingCar car:cars) {
oneClass.append("<option value='");
oneClass.append(car.getId());
oneClass.append("'>");
for(int i=0;i<num;i++) {
oneClass.append(" ");
}
oneClass.append("|--");
oneClass.append(car.getName());
oneClass.append("</option>");
getChildClass(oneClass, car.getId(),num);
}
}
return oneClass;
}