2

I am using KnockBack (w/ KnockOut & BackBone) and am having trouble getting KB CollectionObservable (CO) values in the same format as KO's ObservableArrays. This is the core essence of KB, of course -- allowing me to use BB models with KO's data-binding; this is why I am so surprised I can't get/use the same syntax to expose the data to the data-binding.

Consider the following:

x = ko.observableArray([[1,2],[3,4]])

//x() == [Array[2],  Array[2]]

y = kb.collectionObservable(new Backbone.Collection([[1,2],[3,4]]))

// y() == [ViewModel, ViewModel]

So, assuming I have such a kb.collectionObservable, how can I easily extract its values as an array of arrays, to be used with KO-compatible APIs?

Kjartan
  • 18,591
  • 15
  • 71
  • 96
sellarafaeli
  • 1,167
  • 2
  • 9
  • 24

1 Answers1

0

A ko.computed that loops over the kb.collectionObservable y() with ko.utils.arrayForEach, mapping the objects to arrays and wrapping them in an array, might do the trick.

Pim Schaaf
  • 456
  • 6
  • 16