如何获得 observableArray 的长度? [英] How to get an observableArray's length?
问题描述
我正在尝试创建一系列合同行项目 (CLIN),这些项目将在一般合同信息标题下方显示为单独的 div
元素.
I am attempting to create an array of contract line items (CLINs) that will be displayed as individual div
elements below a header of general contract information.
我能够让正常的 observable 工作,但似乎通过视图模型的构造函数传递数组并没有创建 clins 可观察数组的任何部分.
I am able to get the normal observables to work, but it appears that the passing of the array via the constructor for the view model is not creating any part of the clins observable array.
我有一个 jsFiddle 来说明我的问题.令我感到奇怪的是,HTML span 标签上的 data-bind="text: clins.length()
甚至没有返回零,而是什么都不呈现.
I have a jsFiddle that illustrates my problem. What is strange to me is that the data-bind="text: clins.length()
on the HTML span tag does not even return zero, but instead renders nothing.
无论如何可以在 jsFiddle 中启用调试,还是应该看到警告/错误?
Is there anyway to enable debugging within a jsFiddle or should I see a warning/error?
推荐答案
来自 jsfiddle 页面的错误确实会发送到您的浏览器.
Errors from jsfiddle pages do get sent to your browser.
至于你的错误,试试这个:
As for your error, try this:
<span data-bind="text: clins().length">
这会将 observableArray
转换为 array
并使用数组的 length
属性.
This turns the observableArray
into an array
and uses the array's length
property.
参见更新了jsfiddle.
这篇关于如何获得 observableArray 的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!