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

Possible bug in dependent method login

2 Answers 27 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Sergei
Top achievements
Rank 1
Sergei asked on 08 Mar 2014, 09:39 PM
If I follow http://docs.telerik.com/kendo-ui/getting-started/framework/mvvm/observableobject#creating-a-dependent-method and create a dependent method on my observable object, I can not use other dependent methods within its logic. This forces me to duplicate logic.

Example:
var data = kendo.observable({
            listing: {
               price: 12300
            },
            formatted: {
                total_due: function() {
                    // this works
                    return kendo.toString((this.parent().get("listing.price")* this.parent().get("quantity"))/100, "c");
                    // this crashes with an error
                    return kendo.toString(this.parent().get("total_due")/100, "c");
                }
            },
            quantity: 1,
            total_due: function() {
                return this.get("listing.price")* this.get("quantity")
            }
        })

2 Answers, 1 is accepted

Sort by
0
Sergei
Top achievements
Rank 1
answered on 08 Mar 2014, 09:40 PM
Mistyped the thread title, should be "Possible bug in dependent method logic"
0
Sergei
Top achievements
Rank 1
answered on 09 Mar 2014, 03:46 AM
Answering my own question. Dependent methods can be called directly without get() and seem to work fine this way. 
Probably worth updating the documentation for.

var data = kendo.observable({
            listing: {
               price: 12300
            },
            formatted: {
                total_due: function() {
                    return kendo.toString(this.parent().total_due()/100, "c");
                }
            },
            quantity: 1,
            total_due: function() {
                return this.get("listing.price")* this.get("quantity")
            }
        })
Tags
MVVM
Asked by
Sergei
Top achievements
Rank 1
Answers by
Sergei
Top achievements
Rank 1
Share this question
or