Skip to content

@jeffreyiacono /sencha.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
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,
id: parent.id,
children: parent.children.map { |c| {text: c.text, id: c.id, leaf: true }}
}
end
end
end
end
end
@alexanderscott

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.