gpt4 book ai didi

javascript - 创建的 observableArray 始终为空

转载 作者:数据小太阳 更新时间:2023-10-29 03:53:14 26 4
gpt4 key购买 nike

我想创建一个 observableArray。下面的代码打印“6 : 0”和“3 : 0”,即 observableArrays 是空的。

我已经在 Firefox 5 和 Chrome 11.0.696.68 中对此进行了测试。

我做错了什么?

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

最佳答案

改变:

 console.log(myStringArray.length + " : " + viewStringModel.length);
console.log(myObjectArray.length + " : " + viewObjectModel.length);

 console.log(myStringArray.length + " : " + viewStringModel().length);
console.log(myObjectArray.length + " : " + viewObjectModel().length);

关于javascript - 创建的 observableArray 始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6537684/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com