-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Seperate example to seprate file and bootstrap library
- Loading branch information
Ferdi Schmidt
committed
Aug 12, 2014
1 parent
cb2bf60
commit c89f276
Showing
3 changed files
with
79 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
var NestedSetModel = require('./nested-set-model'); | ||
|
||
// An example input set | ||
/* | ||
1 root 12 | ||
/ \ | ||
2 parent 9 10 middle 11 | ||
/ | ||
3 child 8 | ||
/ | ||
4 child 7 | ||
/ | ||
5 leaf 6 | ||
*/ | ||
|
||
var set = [ | ||
{ | ||
id: 1, | ||
title: 'root', | ||
left: 1, | ||
right: 12 | ||
}, | ||
{ | ||
id: 4, | ||
title: 'child', | ||
left: 3, | ||
right: 8 | ||
}, | ||
{ | ||
id: 2, | ||
title: 'parent', | ||
left: 2, | ||
right: 9, | ||
}, | ||
{ | ||
id: 3, | ||
title: 'middle', | ||
left: 10, | ||
right: 11 | ||
}, | ||
{ | ||
id:5, | ||
title: 'child', | ||
left: 4, | ||
right: 7 | ||
}, | ||
{ | ||
id:6, | ||
title: 'leaf', | ||
left: 5, | ||
right: 6 | ||
} | ||
]; | ||
|
||
var model = new NestedSetModel(set); | ||
|
||
if (model.find({ title: 'child', left: 3}).isLeaf() === false) { | ||
console.info('SUCCESS: {title: "child", left: 3} is not a leaf node'); | ||
} else { | ||
console.error('FAIL: {title: "child", left: 3} is a leaf node, but shouldn\'t be'); | ||
} | ||
|
||
console.log('It\'s parents:', model.find({title: 'child', left: 3}).parents()); | ||
|
||
console.log('It\'s childrne:', model.find({title: 'child', left: 3}).children()); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters