改变ko.observable的价值 [英] changing value of ko.observable

查看:110
本文介绍了改变ko.observable的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为totalLength的对象的ko.observable属性。在使用应用程序时,我想在物理上修改此属性的新值。我该怎么做?

I have a ko.observable property of an object called "totalLength". While using application I would like to physically amend new value to this property. How can I do that?

我可以通过以下方式预览所需物业的价值:

I can preview the value of the demanded property by displaying:

alert(feature.totalLength());

所以我知道它就是那个。但是当我给它分配一个新值时:

so I know that it is the one. But when I assign a new value to it:

feature.totalLength() = 10;

我收到错误:

ReferenceError :左侧无效分配

ReferenceError: invalid assignment left-hand side

为什么?

推荐答案

ko.observable 是一个函数,所以你需要像这样设置值 feature.totalLength(10)

ko.observable is a function so you need to set the value like this feature.totalLength(10).

这篇关于改变ko.observable的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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