I want to create an observableArray. The code below prints "6 : 0 " and "3 : 0", i.e. the observableArrays are empty.
I've tested this in Firefox 5 and Chrome 11.0.696.68.
What am I doing wrong?
var myStringArray = new Array( "Bungle", "Bear", "George", "Hippo", "Zippy", "Unknown" );
var myObjectArray = new Array(
{ name: "Bungle", type: "Bear" },
{ name: "George", type: "Hippo" },
{ name: "Zippy", type: "Unknown" }
);
var viewStringModel = ko.observableArray( myStringArray );
var viewObjectModel = ko.observableArray( myObjectArray );
console.log(myStringArray.length + " : " + viewStringModel.length);
console.log(myObjectArray.length + " : " + viewObjectModel.length);
change:
console.log(myStringArray.length + " : " + viewStringModel.length);
console.log(myObjectArray.length + " : " + viewObjectModel.length);
to
console.log(myStringArray.length + " : " + viewStringModel().length);
console.log(myObjectArray.length + " : " + viewObjectModel().length);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With