Skip to content

Commit a6b0bf8

Browse files
committed
Add getAncestors to joint.dia.cell
1 parent 02f15a0 commit a6b0bf8

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/joint.dia.cell.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,27 @@ joint.dia.Cell = Backbone.Model.extend({
261261
return this;
262262
},
263263

264+
getAncestors: function(){
265+
266+
var ancestors = [],
267+
parentId = this.get('parent');
268+
269+
if(this.collection === undefined)
270+
return ancestors;
271+
272+
while(parentId !== undefined) {
273+
var parent = _.find(this.collection.models, function(item){ return item.id === parentId; });
274+
if(parent !== undefined) {
275+
ancestors.push(parent);
276+
parentId = parent.get('parent');
277+
} else {
278+
break;
279+
}
280+
}
281+
282+
return ancestors;
283+
},
284+
264285
getEmbeddedCells: function(opt) {
265286

266287
opt = opt || {};

0 commit comments

Comments
 (0)