Reputation: 361
So I've got two versions of this question, one a little simplified, one a bit more like what I'm trying to achieve.
Is there some way I can pass in another argument (eg, so as return the first in the array)?
In controllers/student
score: function(){
return this.get('scores', 1);
}.property('scores')
An extra dimension here. The "score" model also belongs To an "objective" model. Can I set the "score" property on my "student" controller depending on the id of a chosen objective?
-------------------------------------------Update----------------------------------------------------------
I'm afraid I'm still stuck! I've been trying to figure out a little more but to no avail. I'll outline a little code to hopefully make my issue clearer.
My models
student
scores: DS.hasMany('score', {async: true}),
name: DS.attr('string')
objective
name: DS.attr('string'),
scores: DS.hasMany('score', {async : true})
score
scoreResult: DS.attr('number'),
objective: DS.belongsTo('objective', {async: true}),
student: DS.belongsTo('student', {async: true})
So elsewhere, I'll be able choose an objective, gets its objective_id, and then use this to set the student controller's "score" to that for the appropriate objective.
I hope this makes sense. I'm really struggling to find any tutorial/guidance for this, and struggling to figure it out for myself. I'd really appreciate any help.
Upvotes: 0
Views: 513
Reputation: 1414
To answer the question of extra arguments. You can add other arguments by using something like this
score : Ember.computed('first','second','third', function(){
//now use all three properties to do anything here
// you can use any number of properties
return this.get('model').filterBy('first',A);
});
Another syntax but with same meaning will be
score : function(){
}.property('first','second','third')
Upvotes: 0
Reputation: 2725
return this.get('scores.firstObject');
http://emberjs.com/api/classes/Ember.ArrayProxy.html
Upvotes: 1