0

If I have an ember object in coffeescript as per the documentation

Person = Ember.Object.extend
  name: null
  lastName: null
  fullName: Ember.computed ->
    return 'hello'
  .property('name', 'lastName')

person = Person.create
  name: 'Tom'
  lastName: 'Tim'

Using person.get('fullName') returns an ember object instead of the fullname

m =>
    _cacheable: true
    _dependentKeys: Array[1]
    0: "ownerships"
    length: 1
    __proto__: Array[0]
    func: function () {
    __proto__: Ember.Descriptor

Because of this (I assume), I see [object Object] instead of the fullName

<script type="text/x-handlebars" data-template-name="personView">
{{#with App.peopleController.person}}
  <dt>First name</dt>
  <dd>{{name}}</dd>
  <dt>Fullname</dt>
  <dd>{{fullName}}</dd>
{{/with}}
</script>

This renders:

First name
[object Object]
scottkf
  • 67
  • 1
  • 8
  • Could you provide a jsfiddle ? I don't know towerjs, but it seems that `@get('ownerships').where(hours: ">": 0).count()`return an object (perhaps a relation object) – sly7_7 Aug 19 '12 at 19:01
  • I think it'd be difficult to provide a fiddle, but I figured it was coffeescript related, you could be right, I'll check! – scottkf Aug 19 '12 at 19:21
  • It would appear that it's not that easy, even if I removed that line and say something like `return "hello"` it still shows up as an object. I updated the post – scottkf Aug 19 '12 at 19:23

1 Answers1

1

Pointing coffeescript gave me a hint: try to define fullName like this:

fullName: (->
   return "hello"
).property('firstName', 'lastName')

I think in your example the value returned is the function itself, not the value.

EDIT

I tried to translate your code in javascript with: http://tinyurl.com/9mh2eho

Then, paste in a jsfiddle:

http://jsfiddle.net/Sly7/ksRkd/

Both versions seem to work...Perhaps the mistake is somewhere else.

sly7_7
  • 11,961
  • 3
  • 40
  • 54
  • I'd say it's probably returning the function itself too, because when I do `fullName: 'hello'` instead of the function it correctly returns the right thing, maybe it has to do with the context of the model, I'll have to ask in tower I suspect – scottkf Aug 19 '12 at 19:45
  • Yep, perhaps with the link I gave, you can translate your code in js, and then create a js fiddle. – sly7_7 Aug 19 '12 at 19:47
  • I'll give it a try, but I'm beginning to think this is related to how tower uses getters and setters. I appreciate your help! – scottkf Aug 19 '12 at 19:55
  • It turns out it was just a matter of syntax. Tower's Model doesn't directly subclass Ember's object, but merely uses it as a proxy, so I had to define the function fullName the same way I would define a property 'name'. Thanks for the help! – scottkf Aug 19 '12 at 20:49
  • Fine, I think you can post your solution as an answer, and accept it. It could be usefull to others :) – sly7_7 Aug 19 '12 at 20:52