{
"name": "buchix",
"dependencies": {
"handlebars": "2.0.0",
"jquery": "^1.11.1",
"ember": "1.9",
"ember-data": "1.0.0-beta.12",
"ember-resolver": "~0.1.7",
"loader.js": "stefanpenner/loader.js#1.0.1",
"ember-cli-shims": "stefanpenner/ember-cli-shims#0.0.3",
"ember-cli-test-loader": "rwjblue/ember-cli-test-loader#0.0.4",
"ember-load-initializers": "stefanpenner/ember-load-initializers#0.0.2",
"ember-qunit": "0.1.8",
"ember-qunit-notifications": "0.0.4",
"qunit": "~1.15.0",
"ember-simple-auth": "~0.7.1",
"momentjs": "~2.8.4",
"bootstrap": "~3.3.1"
}
}
我有一个简单的应用程序,模型“人”和模型“周”(1:n关系)。
模型“person”具有计算属性“currentWeek”,它返回当前周(按“year”和“calendarWeek”等属性过滤)。这里一切都很好。 问题是,当我的控制器的查询参数(calendarWeek,year)发生变化时,我需要这个属性来重新计算。但是无法像我这样访问我的模型中的查询参数
currentWeek: function() {
var self = this;
var weeks = this.get('weeks').filter(function(week) {
return week.get('kw') === 50 && week.get('year') === 2014;
});
return weeks.objectAt(0);
}.property('kw', 'year'),
如何将查询参数注入我的ember-data-model中,以便我可以在每次查询-param更改时重新计算属性?
答案 0 :(得分:0)
答案很简单。我试图将逻辑放入模型中。但我必须把它放入一个控制器。我的ArrayController类型的PersonController应该像这样指定一个ItemController。
App.PersonsController = Ember.ArrayController.extend({
itemController: 'person'
});
App.PersongController = Ember.ObjectController.extend({
currentWeek: function() {
var self = this;
var weeks = this.get('weeks').filter(function(week) {
return week.get('kw') === 50 && week.get('year') === 2014;
});
return weeks.objectAt(0);
}.property('kw', 'year')
});
现在我可以访问' kw'和'年'例如,通过依赖注入。