samedi 4 septembre 2021

Ember.set not working on some specific property

I am not a beginner in Ember.js but I don't understand why the following bug occurs:

console.log('--> before set document', JSON.stringify(model.echographies));
model.echographies.pushObject(EmberObject.create({test: '1'}));
model.echographies.forEach(echography => {
  if (!echography.documents) {
    set(echography, 'documents', []); // <== bug is here
    set(echography, 'documentsX', []);
    set(echography, 'documentsY', 'test');
  }
});
console.log('--> after set document', JSON.stringify(model.echographies));

The output in the console is:

    --> before set document 
    [
        {"id":92,"echography_date":"2020-02","echography_freetext":"echography_freetext"}
    ]
    --> after set document 
    [
        {"id":92,"echography_date":"2020-02","echography_freetext":"echography_freetext","documentsX":[],"documentsY":"test"},
        {"test":"1","documents":[],"documentsX":[],"documentsY":"test"}
    ]

What I don't understand is why the documents property is not set on the real object while documentsX or documentsY work on it and why the three properties work on the fake object. I could not make a JSFiddle to reproduce the bug.

Ember 3.16 Objects are created with EmberObject.create. The array is displayed in the view with a and some computed watching the array.

Do you have any idea on why this bug could append? What should I try to debug this code and find why the set not working for this specific property?




Aucun commentaire:

Enregistrer un commentaire