keystonejs/keystone-classic

Can't save NumberArray

Open

#4629 aperta il 7 mag 2018

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)JavaScript (2288 fork)batch import
help wantedquestion

Metriche repository

Star
 (14.656 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

I'm using KeystonJS and I'm trying to update a NumberArray by index, but when I save the change, it doesn't save it in the admin UI.

Here's my code :

Project.model.findOne({projectId: projectId}).exec(function(err, project){
    if (err) return res.apiResponse({statusCode: 500, message: err});
    if (!project) return res.apiResponse({ statusCode: 400, message: "Can't find this projects" });
    console.log("BEFORE : " + project.detailsPerc[index]);
    project.detailsPerc[index] += 40;
    // project.progressionPerc += 10;

    project.save(function(err, result) {
        if(err) {
            console.log(err);
            res.apiResponse({
                statusCode: 400,
                items: err
            });
        }
        else {
            console.log("RESULTAT :" + result);
            console.log("AFTER : " + project.detailsPerc[index]);
            res.apiResponse({
                statusCode: 200,
                items: project
            });
        }
    })
})

The result is good :

RESULTAT :{ _id: 5ab158fb87475e062c0122c9,
clientId: '1',
__v: 2,
client: 5ad5f4aaa42faf03b95cacf6,
detailsPerc: [ 40, 0, 0 ],
details: [ 'Masterisation', 'EMM', 'Developpement' ],
progressionPerc: 20,
projectId: '1',
name: 'jarviis' }

But yet when I go in the admin UI, my array still show me [0,0,0]. Also, it works when I update project.progressionPerc.

Does anyone know what I'm doing wrong? Thanks guys!

Software Version
Keystone 4.0.0-beta5
Node v9.8.0

Guida contributor