Skip to content

Instantly share code, notes, and snippets.

@JeffGos
Created August 7, 2014 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffGos/a4418b7e0116a22092c9 to your computer and use it in GitHub Desktop.
Save JeffGos/a4418b7e0116a22092c9 to your computer and use it in GitHub Desktop.
Knockoutjs add array of items to observableArray
ko.observableArray.fn.pushAll = function (valuesToPush) {
var underlyingArray = this();
this.valueWillMutate();
ko.utils.arrayPushAll(underlyingArray, valuesToPush);
this.valueHasMutated();
return this;
};
var viewModel = {
valuesArray : ko.observableArray([])
};
ko.applyBindings(viewModel);
//push a new array onto the existing one
viewModel.valuesArray.pushAll([{}, {}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment