Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
module that generates json for usage by sencha touch 2 nested list menu component
module Sencha
module NestedListMenu
class << self
# Sencha Touch nested list menu requires json in the form of:
# {"text": "some identifier",
# "children": ["text": "child identifier", "other": "info", "leaf": "true"],
# [ ... ]
# },
# { ... }
# Note the "leaf" : "true" within the children element. This is important to indicate
# this is the leaf of the nested tree menu for Sencha.
# You can override "text" and "children" to be whatever you want.
# The method takes a set of records as a param and converts the parent / children records into the desired
# syntax. Here, the records are simply named parents and children, change as needed.
def nested_list_json(parents)
parents.reduce([]) do |agg, parent|
agg << { text: parent.text,
children: { |c| {text: c.text, id:, leaf: true }}

Hey Jeffrey, could you please explain a bit on how to run this against an existing json doc to generate sencha-nestedlist-friendly json? I've been struggling a bit to get a large json doc into this leaf-format. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.