Bookshelf.js – 更新logging后,初始页面加载/查询显示旧logging。 刷新数据正确显示后

当我使用书架将列设置为空,并redirect到显示该数据的页面时,数据将显示未更新的logging,直到我刷新。 代码如下:

Table.where({id: req.param.id}).fetch() .catch(function (err) { console.log(err); }) .then(function (results) { results.set('other_column', null); results.save(); results.refresh(); // Redirect to orders page res.redirect('/landing-page'); }); 

着陆页查询是这样的:

  Table.where({id: req.param.id}).fetch() .catch(function (err) { console.log(err); }) .then(function (results) { data.results = results.attributes; res.render('display-page', data); }); 

有谁知道我如何获取更新的logging,或让我知道如果我更新logging不正确? 任何帮助解决这个问题将不胜感激,因为我不能用旧的数据渲染页面后,用户刚刚更新…

你正在写保存数据,如同步代码,所以save()可能(并经常会)在refresh() 之后发生。 尝试将其更改为:

  Table.where({id: req.param.id}).fetch() .catch(function (err) { console.log(err); }) .then(function (results) { return results .set('other_column', null) .save(); }) .then(function (results) { // results should now include the saved data // Redirect to orders page res.redirect('/landing-page'); });