mercredi 18 novembre 2015

Ember hasMany and size of array(s)

I have a relation hasMany and I want get the next index number. So, in my controller I have :

    nextStepIndex: Ember.computed(function () {
        return this.get('floor').get('steps').get('length') + 1;
    }).property('nextStepIndex')

I used too :

    nextStepIndex: Ember.computed(function () {
        return this.get('floor').get('steps.length') + 1;
    }).property('nextStepIndex')

But the length is always 0. The step is not saved and the floor too. All object was just created with createdRecord and the step is added with pushObject.

I saw in the steps relation they have a lot or array :

   DS.PromiseManyArray 
   DS.PromiseArray
   ArrayProxy
   MutableArray
   Array

My "step" object is in the ArrayProxy. So when I call the length method what size I will obtain?

So, if I can get the child record in the {{#each}} template directive, I expect to have the right size when I call the length method.

I known I can get the ArrayProxy size, but I don't want make a assumption on the implementation.




Aucun commentaire:

Enregistrer un commentaire