jeudi 3 novembre 2016

How to bind to hasMany length on Ember Data model without triggering a network request

Let's say I'd like to have a computed property called hasChildren on my ember data model that looks like this.

import Ember from 'ember';
import Model from 'ember-data/model';
import { hasMany } from 'ember-data/relationships';

export default Model.extend({

  children: hasMany(),

  hasChildren: Ember.computed('children.[]', function() {
    return this.hasMany('children').ids().length > 0;
  })

});

Unfortunately, the above still triggers a trip to the server.

One of the workarounds I can think of is to have a volatile computed property.

However, I would like to know if there's a way to bind to hasMany.length and not trigger a network request. Or maybe there's a way to bind to the hasMany.ids or hasMany.value somehow.




Aucun commentaire:

Enregistrer un commentaire