changing value of ko.observable

2019-02-07 22:06发布

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;

I get an error:

ReferenceError: invalid assignment left-hand side

Why?

2条回答
你好瞎i
2楼-- · 2019-02-07 22:35

You can change value of observable like this:

feature.totalLength(10)
查看更多
We Are One
3楼-- · 2019-02-07 22:36

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

查看更多
登录 后发表回答