Reputation: 372
I would like to make the following code work if at all possible. The goal is to have a computed property that depends on a list of strings by using Javascripts "apply" method.
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/apply
App.View = Em.View.extend
myProps: ['content.prop1', 'content.prop2']
myComputed : (->
return "super valuable things"
).property.apply(@get("myCompted"), @get("myProps"))
So far...no luck. It just seems to reject my most earnest desire to make this work.
Any help would be supremely appreciated! Steve
Upvotes: 2
Views: 91
Reputation: 3973
You don't need to use the apply
function and I'm not sure why you think you need to do that. The property function only wants an argument of the property it depends upon. In this case it is 'myProps'
. You do not need to get
that property either, Ember will work it all our for you.
Take a look at this jsfiddle and you'll see what I mean. You can do all your manipulation of the array inside the myComputed
property and the array will have been made available for you already.
App.ApplicationView = Em.View.extend({
myProps: ['123', '456'],
myComputed : function () {
return this.get('myProps');
}.property('myProps')
});
Upvotes: 2