开发者

Created observableArray is always empty

开发者 https://www.devze.com 2023-03-16 06:54 出处:网络
I want to create an observableArray. The code below prints \"6 : 0 \" and \"3 : 0\", i.e. the observableArrays are empty.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消