简体   繁体   中英

How to structure Models for Folder and File items using Backbone.js

I'm working on a project to more or less replicate a OS X Finder using web technologies.

Having decided to use Backbone.js and read this useful tutorial on structuring my code I have come to a bit of a conceptual problem.

How do I best model the relationship between Folders and Files (where files can be multiple types) using Backbone?

Should my basic Model be a File with Folders an extension of it?

Or would it be better to make them separate Models.

Given I need to make 'shared', 'recent' and 'favourite' views that can contain both Folders and Files how does this relationship work?

EDIT Well as so often happens I continued Googling and found this add-on to Backbone which seems to be exactly what I need. If anyone has any further advice I'd be happy to hear it though.

I would make them separate models since they really are different concepts. Alternatively you could just have File, each containing a path property with the full path from the root. you might end up having to do a lot of parsing though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM