Questions tagged [ko.observablearray]

An observableArray is a knockout.js construct similar to a regular array in JavaScript, except that it allows for observing changes to the collection (e.g. adding and removing items).

An observableArray is a knockout.js construct similar to a regular array in JavaScript, except that it allows for observing changes to the collection (e.g. adding and removing items).

To quote the introduction from the relevant knockout.js documentation:

If you want to detect and respond to changes on one object, you’d use observables. If you want to detect and respond to changes of a collection of things, use an observableArray. This is useful in many scenarios where you’re displaying or editing multiple values and need repeated sections of UI to appear and disappear as items are added and removed.

var myObservableArray = ko.observableArray();    // Initially an empty array
myObservableArray.push('Some value');            // Adds the value and notifies observers

To see how you can bind the observableArray to a UI and let the user modify it, see the simple list example.

Key point: An observableArray tracks which objects are in the array, not the state of those objects.

228 questions
-2
votes
1 answer

Array change subscriptions returning undefined

Below is a small poc i was working on depicting various functionalities of knockout. I want to call the subscribe method for observableArray, but it returns undefined, i tried two different ways, i am unable to understand what is incorrect. any…
Nitesh
  • 1,241
  • 4
  • 16
  • 25
-2
votes
1 answer

Knockout: can't we just use observable instead of observablearray

giving the fact that a JavaScript array is specific type of an javascript object (an associative array), can't we just use ko.observable() instead of ko.observableArray()? especially if we are NOT interested in observing changes in an array…
Abdu
  • 487
  • 4
  • 12
-2
votes
1 answer

knockout observable array push adding only first object

I have an observable array. Assume that (object) data has Id, Name, Description self.SelectedObjects = ko.observableArray(); self.SelectedObjects.push(data); self.SelectedObjects.push(data); Line number 1 and 2 work fine. At line number 3 the…
Ahmad
  • 1
  • 1
  • 1
1 2 3
15
16