public JsonResult getNodeContent2(String parentCategory) { if (parentCategory == "") { parentCategory = "null"; } String categoriesString = categoryTable.Get("parentCategory", parentCategory); if (categoriesString == null) { return(null); //there are no subcategories } JArray categoriesObject = JsonConvert.DeserializeObject <JArray>(categoriesString); JArray newobjs = new JArray(); foreach (JObject obj in categoriesObject) { JObject obj1 = new JObject(); obj1["id"] = obj["_id"]; obj1["text"] = obj["name"]; obj1["hasChildren"] = true; // obj1["items"] = new JArray(); // obj1["items"] = "[]"; obj1["spriteCssClass"] = "objectimg"; newobjs.Add(obj1); } return(Json(JsonConvert.SerializeObject(newobjs), JsonRequestBehavior.AllowGet)); }
/// <summary> /// This method allows to get the document's childs by id /// </summary> /// <param name="parentCategory"> /// The category's id that we want to find its children /// </param> /// <author> /// Luis Gonzalo Quijada Romero /// </author> /// <returns> /// Returns an array with the information needed to represent a tree /// </returns> public JsonResult getNodeContent(String parentCategory) { if (parentCategory == "") { parentCategory = "null"; } String categoriesString = _categoryTable.Get("parentCategory", parentCategory); if (categoriesString == null) { return(null); //there are no subcategories } JArray categoriesObject = JsonConvert.DeserializeObject <JArray>(categoriesString); foreach (JObject category in categoriesObject) { try { //try to remove customFields, if can't be removed it doesn't care category.Remove("customFields"); } catch (Exception e) { /*Ignored*/ } try { category.Remove("parentCategory"); } catch (Exception e) { /*Ignored*/ } try { category.Remove("CreatedDate"); } catch (Exception e) { /*Ignored*/ } try { category.Remove("LastmodDate"); } catch (Exception e) { /*Ignored*/ } } categoriesString = JsonConvert.SerializeObject(categoriesObject); return(Json(categoriesString)); }