The problem is that whatever $(jsonData.rows) returns probably isn't a
plain javascript array.
You should be able to use $(jsonData.rows).get() to get an actual array.
But really you shouldn't be replacing the data in the array as if it
were a plain observable, using the convenience methods is much more
robust. e.g.
viewModel.theArray.splice.apply(viewModel.theArray,
[0,0].concat($(jsonData.rows).get()));
This will essentially construct a function call that looks like: (see [2])
var results = $(jsonData.rows);
viewModel.theArray.splice(0,0, results[0], results[1], ...);
which replaces the previous empty arrays contents with the results
array, without actually replacing it with a new array object (which is
what the observable(value) syntax does with observable arrays).
You could essentially loop through the data and use .push but the
above method guarantees a single value mutation notification to any of
the arrays dependents.
[1]: http://www.w3schools.com/jsref/jsref_splice.asp
[2]: http://vikasrao.wordpress.com/2011/06/09/javascripts-call-and-apply-methods/
>
> that I then try and prepend one row to at the beginning with:
>
> viewModel.theArray.unshift({objID:"", objLabel:"Select Your
> Choice..."});
>
> I'm getting an error in Firebug of "TypeError:
> underlyingArray[methodName] is undefined" on line 775 of the debug
> knockout-1.2.1.js.
>
> My array is made up of JS objects, not simple strings. Can unshift
> handle this?
--
-barkmadley
sent from an internet enabled device
http://barkmadley.com