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

ObservableObject double dependent fields

1 Answer 69 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bart
Top achievements
Rank 1
Bart asked on 26 Jul 2013, 07:33 PM
Consider the following code. Within the incidentPercentage method, I am using another dependent method, but I am not able the use the recommended "this.get" syntax here. The only way I could get it to work was to call the other dependent methods directly. Please advise. Is this OK to do?

var viewModel = kendo.observable({
  dataItem: {},
  details: function() {
    return this.get('dataItem').details;
  },
  hourCount: function() {
    var dataItem = this.get('dataItem');
    return (dataItem.hasOwnProperty('status') ? dataItem.status.length : 0);
  },
  incidentCount: function() {
    return _.without(this.get('dataItem').status, 1, true).length;
  },
  incidentPercentage: function() {
    return Math.round(
      this.incidentCount() / this.hourCount() * 100
    );
  }
});

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 30 Jul 2013, 03:06 PM
Hello Bart,

 Yes this is ok to do as long as the dependent method uses get("") to access fields. This should still setup the correct dependency chain.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
General Discussions
Asked by
Bart
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or