diff --git a/src/array/ArrayElement.js b/src/array/ArrayElement.js index 0edc615..ab91eff 100644 --- a/src/array/ArrayElement.js +++ b/src/array/ArrayElement.js @@ -46,6 +46,11 @@ define(["array/ArrayItemElement"], function(ArrayItemElement) { element.insertBefore(child.clone(), element.firstChild); }; + this.insertAtIndex = function(index) { + + element.insertBefore(child.clone(), element.children[index]); + }; + this.removeFirst = function() { if (element.firstElementChild) { @@ -62,6 +67,11 @@ define(["array/ArrayItemElement"], function(ArrayItemElement) { } }; + this.removeAtIndex = function(index) { + + element.removeChild(element.children[index]); + }; + this.removeChildren = function() { var children = [].slice.call(element.children); diff --git a/src/array/method/Splice.js b/src/array/method/Splice.js index 84f09fe..55551f6 100644 --- a/src/array/method/Splice.js +++ b/src/array/method/Splice.js @@ -38,12 +38,12 @@ define([ for (var i = 0; i < elements.length; i++) { - var element = elements[i].get(); + var element = elements[i]; var end = Math.min(start + deleteCount, model.length) - 1; for (var j = end; j >= start; j--) { - element.removeChild(element.children[j]); + element.removeAtIndex(j); } properties.splice(start, deleteCount); @@ -60,11 +60,10 @@ define([ for (var j = 0; j < elements.length; j++) { - var element = elements[j].get(); - var child = elements[j].getChild(); + var element = elements[j]; - element.insertBefore(child.clone(), element.children[start]); - property.applyBinding(new DOMElement(element), start, model); + element.insertAtIndex(start); + property.applyBinding(new DOMElement(element.get()), start, model); } } }