开发者

storing a filesystem tree in mongodb and serve as json to a flex application

I want to store a filesystem tree into MongoDB within a Ruby application, so we are talking about json/bson representation of something like:

/
/foo
/foo/one
/foo/bar/two
/foo/bar/three
/four

my aim is to store it efficiently and to serve it via json to an Adobe Flex application which will display it in a Tree component.

which is the best solution in your opinion?

this document suggests some options. i'd like to go for something like the first pattern (keeping in mind the limit of 16Mb document size) with this format:

开发者_如何学运维{"/" => [{"foo" => ["one", {"bar" => ["two", "three"]}]}, "four"]}

what do you think? is this a good format to store a hierarchical filesystem tree?

any suggestion is appreciated.


There are many ways to solve this problem, but here is the solutions that will be the easiest for Flex (not the server).

The example data you posted is a bit weird IMO. By default, the Flex tree component takes in an Object (of whatever types) and looks to see if there's a property called 'children' in it, if there is, it branches out from there.

So, if you wanted to display that directory structure in a tree component, you would send a JSON similar to this:

{name:'/', children:[{name:'foo', children:[{name:'one'},{name:'bar', children:[{name:'two'},{name:'three'}]}]},{name='four'}]}

Make sense?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜