Commit a6190aee authored by Jamie Carl's avatar Jamie Carl 🤙🏼

Fixed remove not working with int values

If the arg was an int, we assumed it was the index to remove, which was stupid.  Now I have split these functions out so that remove() will remove by value and the new unset() method will remove by index.
parent cb422971
Pipeline #1834 passed with stage
in 20 seconds
......@@ -398,7 +398,7 @@ dataBinderArray.prototype._attr_name = function (attr_name) {
dataBinderArray.prototype.pop = function () {
var index = this._elements.length - 1;
var element = this._elements[index];
this.remove(index);
this.unset(index);
return element;
};
......@@ -458,10 +458,22 @@ dataBinderArray.prototype.indexOf = function (searchString) {
return -1;
};
dataBinderArray.prototype.remove = function (index) {
if (index instanceof dataBinderValue) index = index.value;
if (typeof index === 'string') index = this.indexOf(index);
if (index < 0 || typeof index === 'undefined') return;
/**
* Remove an item value from the array
*
* @param {any} value The value to remove.
*/
dataBinderArray.prototype.remove = function (value) {
return this.unset(this.indexOf(((value instanceof dataBinderValue) ? value.value : value)));
};
/**
* Remove an item from the array using it's index in the array
*
* @param {any} index The index of the item to remove.
*/
dataBinderArray.prototype.unset = function (index) {
if (index < 0 || typeof index !== 'integer') return;
var element = this._elements[index];
if (element instanceof dataBinder) jQuery('[data-bind="' + this._attr_name() + '"]').children().eq(index).remove();
this._cleanupItem(index);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment