extjs 怎么通过ajax把list集合的每个返回值显示到页面。

2024-12-18 23:41:45
推荐回答(1个)
回答1:

第三类库提供吧象封装JSON象我用
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public void list(HttpServletRequest request, HttpServletResponse response,PrintWriter pw){
PartsDao dao = new PartsDao();
List partsList = dao.getList();
JSONObject items = new JSONObject();
JSONArray result = null;
try {
result = new JSONArray();
for (int i = 0; i < partsList.size(); i++) {
Parts parts = (Parts)partsList.get(i);
JSONObject jsonParts = new JSONObject();
jsonParts.put("ID", parts.getPartsId());
jsonParts.put("name", parts.getName());
jsonParts.put("PP", parts.getBrand());
jsonParts.put("LGBH", parts.getLGBH());
jsonParts.put("TH", parts.getTH());
jsonParts.put("YCBH", parts.getYCBH());
jsonParts.put("DW", parts.getFormat());
jsonParts.put("GG", parts.getAttribute());
jsonParts.put("BZ", parts.getRemark());
jsonParts.put("status", parts.getStatus() == 1 ? "1" : "0");
result.add(jsonParts);
}
} catch(Exception ex) {
ex.printStackTrace();
}
items.put("identifier", "ID");
items.put("label", "name");
items.put("items", result);
items.write(pw);
}