Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/allouis/backbone.nest
Backbone plugin that enables infinitely nested Collections within Models.
https://github.com/allouis/backbone.nest
Last synced: 24 days ago
JSON representation
Backbone plugin that enables infinitely nested Collections within Models.
- Host: GitHub
- URL: https://github.com/allouis/backbone.nest
- Owner: allouis
- Created: 2013-06-27T20:49:15.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-09-06T13:26:26.000Z (about 11 years ago)
- Last Synced: 2024-04-15T15:35:03.070Z (7 months ago)
- Language: CSS
- Homepage:
- Size: 180 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
backbone.nest
=============Backbone plugin that enables infinitely nested Collections within Models, and advanced data structure.
Basic Concept
=============Simply use `Backbone.Nest` instead of `Backbone.Model`, and use `{ parse: true }` when creating model.
The rest is taken care of, set the nest attribute to be the collection you want created, and the nests
attribute as a space seperated list of the attributes to be turned into collections.How to use
==========var LevelOneModel = Backbone.Nest.extend({
//stuff
})var LevelOneModels = Backbone.Collection.extend({
model: LevelOneModel})
var LevelTwoModel = Backbone.Nest.extend({
nest: LevelOneModels,
nests: "levelOne"
//stuff})
var LevelTwoModels = Backbone.Collection.extend({
model: LevelTwoModel})
var LevelThreeModel = Backbone.Nest.extend({
nest: LevelTwoModels,
nests: "levelTwo"
//stuff})
var data = {
id:0,
levelTwo:[
{
id: 1,
levelOne:[
{
id:1.1
},
{
id:1.2
}
]
},
{
id: 2,
levelOne:[
{
id:2.1
}
]
},
{
id: 3,
levelOne:[
{
id:3.1
},
{
id:3.2
},
{
id:3.3
}
]
}
]}
var myModel = new LevelThreeModel(data, {parse:true});
myModel.get("levelTwo").get(3).get("levelOne").each(function(mod){
console.log(mod.get("id")) // 3.1, 3.2, 3.3
})