mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
Merge pull request #1482 from alexisfontaine/container-add-empty-array
Handle adding empty children arrays to a container
This commit is contained in:
commit
a54cfcae48
@ -109,22 +109,27 @@ export abstract class Container<
|
|||||||
* add a child and children into container
|
* add a child and children into container
|
||||||
* @name Konva.Container#add
|
* @name Konva.Container#add
|
||||||
* @method
|
* @method
|
||||||
* @param {...Konva.Node} child
|
* @param {...Konva.Node} children
|
||||||
* @returns {Container}
|
* @returns {Container}
|
||||||
* @example
|
* @example
|
||||||
* layer.add(rect);
|
* layer.add(rect);
|
||||||
* layer.add(shape1, shape2, shape3);
|
* layer.add(shape1, shape2, shape3);
|
||||||
|
* // empty arrays are accepted, though each individual child must be defined
|
||||||
|
* layer.add(...shapes);
|
||||||
* // remember to redraw layer if you changed something
|
* // remember to redraw layer if you changed something
|
||||||
* layer.draw();
|
* layer.draw();
|
||||||
*/
|
*/
|
||||||
add(...children: ChildType[]) {
|
add(...children: ChildType[]) {
|
||||||
if (arguments.length > 1) {
|
if (children.length === 0) {
|
||||||
for (var i = 0; i < arguments.length; i++) {
|
return this;
|
||||||
this.add(arguments[i]);
|
}
|
||||||
|
if (children.length > 1) {
|
||||||
|
for (var i = 0; i < children.length; i++) {
|
||||||
|
this.add(children[i]);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
var child = children[0];
|
const child = children[0];
|
||||||
if (child.getParent()) {
|
if (child.getParent()) {
|
||||||
child.moveTo(this);
|
child.moveTo(this);
|
||||||
return this;
|
return this;
|
||||||
|
Loading…
Reference in New Issue
Block a user