- Commander = can.Model({
- attributes : {
- upvotes : 'number',
- downvotes : 'number',
- like : 'boolean'
- }
- }, {
- votes : can.compute(function() {
- return this.attr('upvotes') - this.attr('downvotes');
- })
- });
I call votes() in controllers code everyting is ok
But if call votes() in EJS it will say that object has no attr
If I refactor code like that, it will work:
- Commander = can.Model({
- attributes : {
- upvotes : 'number',
- downvotes : 'number',
- like : 'boolean'
- }
- }, {
- init : function() {
- var self = this;
- this.votes = can.compute(function() {
- return self.attr('upvotes') - self.attr('downvotes');
- })
- }
- });
Is it a bug or this can not be avoided?