jeudi 28 mai 2015

Counting model with ember data

I've looked at various examples on Stackoverflow but I don't seem to understand how get('length') really works.

I'm trying to get a count of users in helper model. There is probably something wrong with the way I'm trying to get('length'), but maybe I also need to use hash RSVP to get both the current model and helper model in todo route?

todo.js

export default Ember.Controller.extend({

    count: function() {
        var helper = this.get('helper');
        return helper.user.get('length');
    }.property('helper.user.[]'),

todo.js

export default DS.Model.extend({
    title: DS.attr('string'),
    isCompleted: DS.attr('boolean', {defaultValue: false}),

    list: DS.belongsTo('list', {async: true}),
    user: DS.belongsTo('user', {async: true}),

    comment: DS.hasMany('comment', {async: true}),
    helper: DS.hasMany('helper', {async: true}),
});

todo.hbs

<p>
                    <span class="badge pull-left">14 hands</span>
                    <span class="badge pull-left">{{todo.count}}</span>
                    </p>

helper.js

export default DS.Model.extend({
    user: DS.belongsTo('user', {async: true}),
    todo: DS.belongsTo('todo', {async: true}),
});

todo.js

export default Ember.Route.extend({
  model: function(params){
    // return model
  },




Aucun commentaire:

Enregistrer un commentaire