简体   繁体   English

ko.observableArray()不添加元素

[英]ko.observableArray() not adding elements

I'm trying out KO but have problems getting observableArray to work, the code is very simple 我正在尝试KO但是在使observableArray工作时遇到了问题,代码非常简单

​var test = new ko.observableArray();
var regulararray = [];

test.push("item");
regulararray.push("regularpush");
console.log("the length for ko: " + test.length + " the length for regular array: " +    regulararray.length);​​

For some reason the length of the knockout array is 0 while the regular array length is 1. 由于某种原因,淘汰阵列的长度为0,而常规阵列长度为1。

Why is this happening? 为什么会这样?

使用test().length而不是test.length

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM