如何获得observableArray的长度? [英] How to get an observableArray's length?

查看:265
本文介绍了如何获得observableArray的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个合同行项目(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.

我能够使正常的可观察对象工作,但是看来通过视图模型的构造函数传递数组并不会创建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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆