In observable function, this.get is not a function

3 posts, 1 answers
  1. Jay
    Jay avatar
    90 posts
    Member since:
    Dec 2011

    Posted 10 Mar 2020 Link to this post

    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. Answer
    Ivan Danchev
    Admin
    Ivan Danchev avatar
    2184 posts

    Posted 12 Mar 2020 Link to this post

    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.
  3. Jay
    Jay avatar
    90 posts
    Member since:
    Dec 2011

    Posted 13 Mar 2020 in reply to Ivan Danchev Link to this post

    Well don't I feel silly. Thanks, Ivan!
Back to Top