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

Debugging MVVM Attributes

1 Answer 52 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
axwack
Top achievements
Rank 1
axwack asked on 21 Aug 2012, 02:49 PM
Does anyone know how to debug a databound attribute in MVVM?

For example: I want to see the value of a calculated attribute.

I tried console.debug (this.get(" XXXX"));

This doesnt do anything. Anyone else?

1 Answer, 1 is accepted

Sort by
0
Jeremy Wiebe
Top achievements
Rank 1
answered on 20 Sep 2012, 03:35 PM
The expression this.get('myproperty'only works when you are working within a computed property (in that case 'this' points back to the view model itself.

If you want to set the value of a model property from 'outside' call .get() on the model itself (even for nested objects).  Eg. this.get('customer.name')

For computed properties you can just call the method directly on your model object.  Like this:
var order = kendo.observable({
    OrderNumber: '1234',
    Customer: {
        Name: 'Joe Blow',
        Address: '123 Main Street'
    },
    getSummary: function() {
        return 'Order #' + this.get('OrderNumber') + ' for ' + this.get('Customer.Name');
    });
 
console.log(order.get('OrderNumber'));
console.log(order.get('Customer.Address');
console.log(order.getSummary());
Tags
MVVM
Asked by
axwack
Top achievements
Rank 1
Answers by
Jeremy Wiebe
Top achievements
Rank 1
Share this question
or