keystonejs/keystone-classic

Can't save NumberArray

Open

#4,629 创建于 2018年5月7日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)JavaScript (2,288 fork)batch import
help wantedquestion

仓库指标

Star
 (14,656 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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

贡献者指南