所以我有两个版本的问题,一个稍微简化,一个更像我想要实现的。
我是否可以通过某种方式传递另一个参数(例如,返回数组中的第一个参数)?
在控制者/学生中
score: function(){
return this.get('scores', 1);
}.property('scores')
这里有一个额外的维度。 "得分"模型也属于"目标"模型。我可以设置"得分"我和学生的财产"控制器取决于所选目标的ID?
-------------------------------------------的更新 ---------------------------------------------- ------------
我害怕我还是被困住了!我一直试图想出更多但无济于事。我将概述一些代码,希望能让我的问题更加清晰。
我的模特
学生
scores: DS.hasMany('score', {async: true}),
name: DS.attr('string')
目标
name: DS.attr('string'),
scores: DS.hasMany('score', {async : true})
得分
scoreResult: DS.attr('number'),
objective: DS.belongsTo('objective', {async: true}),
student: DS.belongsTo('student', {async: true})
在其他地方,我可以选择一个目标,得到它的objective_id,然后用它来设置学生控制器"得分"为了适当的目标。
我希望这是有道理的。我真的很难为此找到任何教程/指导,并努力为自己解决这个问题。我真的很感激任何帮助。
答案 0 :(得分:1)
return this.get('scores.firstObject');
答案 1 :(得分:0)
回答额外论点的问题。您可以使用类似
之类的内容添加其他参数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);
});
另一种语法但具有相同含义的将是
score : function(){
}.property('first','second','third')