Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can write a simple model within a model with a simple function like this in your single model ( xfile model you can call it! ) :</p> <pre><code> loadFolders : function() { if (this.get('isDir')) { var self = this; self.subFolders = []; _.each(self.get('files'), function(data) { file = new File(data); self.subFolders.push(file); }); } } </code></pre> <p>and do the same in your view model to render correct tree view.</p> <p>And in your express.js backend ( I'm not familiar with that framework ) you just send proper json to your backbone models.</p> <p>If your data is too long and you want to get each model directory seperately ( when user expand folder in your view ) you can create a model with lots of collections ( or collection with lots of collection ) with the same idea, then fetch data from server in the model, and the backend must support directories, something like this : /api/file/folder1/folder2/file1.txt</p> <p>Another way to do something more magical is using a relational model ( by any backbone extension that provide such feature )</p> <p>If you want to read more about :</p> <p><a href="http://lostechies.com/derickbailey/2012/04/05/composite-views-tree-structures-tables-and-more/" rel="nofollow">A marionette.js example that do the same</a></p> <p><a href="https://github.com/PaulUithol/Backbone-relational" rel="nofollow">Backbone.Relational - a relational extension for bakcbone</a></p> <p>PS : I can't provide more links, so you can search for Backbone.associate, that's another relational extension for backbone</p> <p>PS 2 : You can use coffeescript, its making javascript syntax simpler and more readable.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload