简体   繁体   English

灰烬数据-hasMany关系的过滤对象

[英]Ember-Data - Filter Objects of a hasMany relationship

Ember 1.7 Ember-Data 1.0.9 Beta Fixture-Adapter Yo Ember-generator Ember 1.7 Ember-Data 1.0.9 Beta夹具适配器Yo Ember生成器

I got a user model and a week model. 我有一个用户模型和一个星期模型。 Each user has x weeks and a week has 1 user. 每个用户有x周,一周有1个用户。 (It's a duty roster app). (这是一个值班应用程序)。

I have a week overview which shows all users an the current selected calendar week of each user. 我有一个星期概览,它向所有用户显示每个用户当前选定的日历周。 So i have to select only the selected week of each user. 所以我只需要选择每个用户的选定星期。 If he doesn't have a calendar week yet, i have to create an empty one. 如果他还没有日历周,我必须创建一个空的日历周。

The Question is: how can I filter the relation in the router, model or in the controller so i get only the week which is currently needed? 问题是:如何在路由器,模型或控制器中过滤关系,以便仅获取当前所需的星期? I think the problem is, that i don't use the filter or filterBy function the correct way. 我认为问题是,我没有正确使用filter或filterBy函数。

User model 用户模型

BuchixDienstplan.User = DS.Model.extend({
    name: DS.attr('string'),
    weeks: DS.hasMany('week', {async:true}),
    phone: DS.attr('string'),
    handy: DS.attr('string'),
    mail: DS.attr('string')
});

Week model 周模型

BuchixDienstplan.Week = DS.Model.extend({
    kwyear: DS.attr('number'),
    mo: DS.attr('string'),
    di: DS.attr('string'),
    mi: DS.attr('string'),
    do: DS.attr('string'),
    fr: DS.attr('string'),
    sa: DS.attr('string'),
    so: DS.attr('string'),
    user: DS.belongsTo('user')
});

Users route 用户路线

BuchixDienstplan.UsersRoute = Ember.Route.extend({
    model: function(params) {
        users = this.store.filter('user')
        return users
    }
});

In the frontend the user can select which week to show. 用户可以在前端选择要显示的星期。 I show a list of all users and the week for the selected configuration. 我显示了所有用户的列表以及所选配置的星期。 For each user I only need one special week (eg calendar week 1 for the year 2014, kwyear = 12014) So how can I filter the relation of the user model? 对于每个用户,我只需要一个特殊的星期(例如,2014年的日历周1,kwyear = 12014)那么如何过滤用户模型的关系?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM