secretlm
secretlm

Reputation: 2361

How to access computed properties

I have a Ember.Object like:

App.HelpVideoInfo = Ember.Object.extend({
MyAccount: ['FAe8w0cUCJ0', 'How-to: Change "My Account"'],
StoreInformation: ['UddOjEG-hXw', 'How-to: Change Store Information'],

getSecondAccount:function()
{
    return this.get('MyAccount')[1];
} .property('MyAccount'),
});

I want to binding from my Ember.View to getSecondAccount (computed property). I used:

App.IconMeaningDialogView = Ember.View.extend({
       accountBinding:    'App.HelpVideoInfo.getSecondAccount';
  });

But it doesn't work. Thanks.

Upvotes: 0

Views: 915

Answers (3)

pangratz
pangratz

Reputation: 16153

Your naming conventions are not conform with those from Ember, see Emberist blog post.

You should name classes UpperCase, instances and properties lowerCase. Then the binding works as expected, see http://jsfiddle.net/pangratz666/PQYYH/.

I would also recommend to use the built in array accessor objectAt.

Handlebars:

<script type="text/x-handlebars" >
    {{#view App.IconMeaningDialogView}}
        {{account}}
    {{/view}}
</script>​

JavaScript:

App.helpVideoInfo = Ember.Object.create({
    myAccount: ['FAe8w0cUCJ0', 'How-to: Change "My Account"'],
    storeInformation: ['UddOjEG-hXw', 'How-to: Change Store Information'],

    secondAccount: function() {
        return this.get('myAccount').objectAt(1);
    }.property('myAccount').cacheable()
});

App.IconMeaningDialogView = Ember.View.extend({
    accountBinding: 'App.helpVideoInfo.secondAccount'
});​

Upvotes: 1

musically_ut
musically_ut

Reputation: 34288

You probably don't want to extend an Ember.Object to create your class App.HelpVideoInfo. Instead, if you create a new object there, it would allow you to bind to the properties in the way you want.

However, if you would like to use the App.HelpVideoInfo subclass, then you would have to create an object before you can bind to its properties. An example of how you can do it this: http://jsfiddle.net/74KX7/1/

Upvotes: 0

Ankur Chauhan
Ankur Chauhan

Reputation: 1390

The way to access that property would be as follows

App.IconMeaningDialogView = Ember.View.extend({
    accountBinding: Ember.Binding.from('App.HelpVideoInfo.getSecondAccount')
});

Refer to Advanced Emberjs Bidnings

Upvotes: 0

Related Questions