function getCategoryData(viewName, dataColumn, getChildren, key) { var v = database.getView(viewName); var nav; if (key) { nav = v.createViewNavFromCategory(key); } else { nav= v.createViewNav(); } var ve = nav.getFirst(); var isFirst = true; var result = "["; while (ve) { if (!ve.isTotal()) { var curData = ve.getColumnValues(); if (!isFirst) { result += ","; } result += "{label : \""; if (key) { result += curData[1]; } else { result += curData[0]; } result += "\", value : "; result += curData[dataColumn]; /* for 2 level categories we fetch additional data */ if (getChildren) { var childve = nav.getChild(); var firstChild = true; result += ", children : ["; while (childve) { var childData = childve.getColumnValues(); if (!firstChild) { result += ","; } result += "{label : \""; result += childData[1]; result += "\", value : "; result += childData[dataColumn]; result += "}"; firstChild = false; childve = nav.getNextSibling(childve); } result += "]" } result += "}"; isFirst = false; } ve = nav.getNextSibling(ve); } result += "]"; return result; }