改变 ko.observable 的值 [英] changing value of ko.observable
本文介绍了改变 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屋!
查看全文