gpt4 book ai didi

javascript - 将 JSON 数据发送到 NodeJs 中的 View

转载 作者:行者123 更新时间:2023-12-03 03:20:43 25 4
gpt4 key购买 nike

我正在对 json 进行一些过滤并将其保存在驱动程序变量中。我的驱动程序变量正在返回 JSON 数据,我想将它们原样发送到 View 而不进行任何更改。

我的问题是:如何将驱动程序变量发送到 View ?

router.get('/', function(req, res, next) {
rp(options)
.then(function (repos) {
var obj = repos;
var driver = _.filter( obj.features, ['id', 'tmp_location.20658']);
console.log(driver); })
.catch(function (err) {
// Delete failed...
});
res.render('index', { title: 'Express' });
});

最佳答案

res.render 移动到 rp.then 并将其作为 driver 传递给 res.render 中的另一个属性参数。

router.get('/', function(req, res, next) {
rp(options)
.then(function (repos) {
var obj = repos;
var driver = _.filter( obj.features, ['id', 'tmp_location.20658']);
console.log(driver);
res.render('index', { title: 'Express', driver: driver });
})
.catch(function (err) {
// Delete failed...
});

});

另请阅读此内容How do I return the response from an asynchronous call?

编辑:

您还应该在 catch 处理程序中使用 next

.catch(function (err) {
next(err);
});

关于javascript - 将 JSON 数据发送到 NodeJs 中的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46581206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com