Created
August 7, 2014 15:39
-
-
Save JeffGos/a4418b7e0116a22092c9 to your computer and use it in GitHub Desktop.
Knockoutjs add array of items to observableArray
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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