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", "Georg开发者_C百科e", "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);
精彩评论