jquery操作JSONArray

后台java代码设置


	JSONArray baseArray = new JSONArray();
			try {
				ArrayList<BookMarkWrapper> bwList = bookMarkDAO
						.getDirectoryItemsByParentID(pid);
				for (BookMarkWrapper bw : bwList) {
					JSONObject json = new JSONObject();
					BookMark b = bw.getBookMark();

					json.put("id", bw.getId());
					String directory = b
							.getDirectory()
							.getPropertyValueAsString()
							.substring(
									b.getDirectory().getPropertyValueAsString()
											.lastIndexOf("/") + 1);
					json.put("text", directory);
					json.put("hasChildren", bookMarkDAO
							.getItemsCountByParentID(bw.getId()) > 0 ? true
							: false);
					baseArray.add(json);
				}
				return baseArray.toString();
			} catch (DAOException e) {
				log.error(this.getClass().getName()
						+ " showDirectoryItems method DAOException="
						+ e.toString());
				throw new ServletException(e);
			}

前端js解析:

function fillLeftContent(obj, data) {
	var html = '';
	$.each(
					data,
					function(key) {
						if (data[key]["hasChildren"]) {
							html += '<dd style="border:none;cursor:pointer" ><dl style="border:none;" id="li_left_'
									+ data[key]["id"]
									+ '" ><dt style="border:none;" onclick="$(\'#id_page_0\').css(\'display\',\'none\');$(\'#gopage_err\').css(\'display\',\'none\');isLeftClick=true;loadLeft(\'#li_left_'
									+ data[key]["id"]
									+ '\','
									+ data[key]["id"]
									+ ')">';
							html += '<b></b><span>';
							html += data[key]["text"] + '</span>';
							html += '</dt></dl></dd>';
						} else {
							html += '<dd onclick="$(\'#id_page_0\').css(\'display\',\'none\');$(\'#gopage_err\').css(\'display\',\'none\');loadLeft(\'#li_left_'
									+ data[key]["id"]
									+ '\','
									+ data[key]["id"]
									+ ')" style="border:none;cursor:pointer" id="li_left_'
									+ data[key]["id"] + '"><b></b><span>';
							html += data[key]["text"] + '</span></dd>';
						}
					});
	$(obj).append(html);


你可能感兴趣的:(html,jquery,json,function,String,border)