ember.jstowerjs

computed property not displaying correctly in EmberJS, showing [object Object]


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]

Solution

  • 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.