optional filter callback for getChildren function. close #313

This commit is contained in:
Лаврёнов Антон
2014-03-02 09:25:22 +08:00
parent 3a5b6eb766
commit 86178185bc
2 changed files with 66 additions and 2 deletions

View File

@@ -1387,6 +1387,50 @@ suite('Container', function() {
layer.draw();
});
// ======================================================
test('getChildren may use filter function', function() {
var stage = addStage();
var layer = new Kinetic.Layer();
var group = new Kinetic.Group();
var circle1 = new Kinetic.Circle({
x: 200,
y: stage.getHeight() / 2,
radius: 70,
fill: 'blue',
stroke: 'black',
strokeWidth: 4
});
var circle2 = circle1.clone();
group.add(circle1).add(circle2);
var rect = new Kinetic.Rect({
name : 'test'
});
group.add(rect);
var circles = group.getChildren(function(node){
return node.getClassName() === 'Circle';
});
assert.equal(circles.length, 2, 'group has two circle children');
assert.equal(circles.indexOf(circle1) > -1, true);
assert.equal(circles.indexOf(circle2) > -1, true);
var testName = group.getChildren(function(node){
return node.name() === 'test';
});
assert.equal(testName.length, 1, 'group has one children with test name');
layer.add(group);
layer.draw();
});