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
0
votes
2 answers

ko.mapping.fromJS with an array of JayData objects

When I use an array of custom jaydata objects the result is bizarre. var arr = []; arr.push(new Northwind.Employee()); arr.push(new Northwind.Employee()); var newarr = ko.mapping.fromJS(arr); If the debug is observed, the variable newarr looks…
0
votes
1 answer

Binding a ko.observableArray to list of { value, text } options

This jsFiddle displays the incorrect code for my objective. I'd like every time the user selects a Day for that day to be added/removed to the byday list. Using Knockout 2.1.0. HTML:
0
votes
1 answer

Knockout copying observable array issue

I am trying to copy one observably array to another observable array. I have a form that has a billing address, shipping address and checkbox that when clicked allows the user to copy all of their shipping info to their billing address. The…
0
votes
1 answer

knockout - having slight issue with filtering my data

Edit: I think the problem is in my self.providers = ko.computed(), I'm overwriting my providers array on the filter button click; I've two fiddles up, both have everything in the HTML pane as I'm developing everything locally and it's just easier to…
magenta placenta
  • 1,461
  • 7
  • 22
  • 34
0
votes
1 answer

KO.utils.arrayPushAll adding new element on selection change to another selected box and grid

I am attempting to pull down data from a JSON response that I wrote in MVC4 using the knockout.js library. I have these three areas that need to be populated, the first of which is a multi-select box. I have looked at examples online as well as…
Shawn Gilligan
  • 157
  • 1
  • 7
0
votes
1 answer

Knockoutjs ObservableArray

The following snippet -- results in an empty list-box. Could anyone tell me what am doing wrong?