This is a migrated thread and some comments may be shown as answers.

In observable function, this.get is not a function

2 Answers 352 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 2
Iron
Iron
Veteran
Jay asked on 10 Mar 2020, 07:58 PM

I am new to using kendo observables. I have what seems to be a relatively simple viewmodel:

var viewVmodel  = kendo.observable({
        CategoryValue: 10000
        , CategoryValueDisplay: function() { return kendo.toString(this.get("CategoryValue"), "c0"); }
        , CategoryNumber: function() { return this.get("CategoryValue") * 2; }
        , CategoryNumberDisplay: function() { return kendo.toString(this.get("CategoryNumber"), "c0"); }
        , CategoryEnabled: true
        , CategoryChange: function(e) { console.log("CategoryChange"); }
});

However, when I try to bind to CategoryNumberDisplay as

<div class="bound" data-bind="text: CategoryNumberDisplay"></div>

I get an error: this.get is not a function. Running in Chrome, the console log shows the error. In CategoryNumberDisplay, if  I replace this.get("CategoryNumber") with simply 20000, it works fine.

Here is a dojo. Can someone tell me what I'm doing wrong, as well as explain the difference between CategoryValueDisplay and CategoryNumberDisplay? (which will probably end up being the same answer.)

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Danchev
Telerik team
answered on 12 Mar 2020, 05:22 PM

Hello Jay,

The get method of the observable is used to get property values. However, in this case CategoryNumber is a method. So accessing it in CategoryNumberDisplay (which is also a method) should be done by invoking it instead of using get:

CategoryNumberDisplay: function() {
  return kendo.toString(this.CategoryNumber(), "c0"); 
}, 

The modified dojo example: https://dojo.telerik.com/oNiZIVOq

Regards,
Ivan Danchev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Jay
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 13 Mar 2020, 11:45 AM
Well don't I feel silly. Thanks, Ivan!
Tags
MVVM
Asked by
Jay
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Ivan Danchev
Telerik team
Jay
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or