繁体   English   中英

使用 nodeJs 上的 res.render 将多个数据数组传递给视图

[英]Pass more than one data array to the view using res.render on nodeJs

我的视图中有两个选择,我需要用不同的数组填充每个选择。 如何使用 res.render 传递两个不同的 jons? 我尝试了下面的方法,但没有奏效。

const result1  = {data1: "val1", data2: "val2"}
const result2  = {Otherdata1: "val1xx", Otherdata2: "val2vv"}

res.render('my-view', {array1: result1, array2: result2});

这样,页面正在处理并且永远不会更新。 如果有人可以帮助我,谢谢。

如果没有错误,此页面将成功发送到浏览器,但不会呈现,因为浏览器希望接收 json 内容而不是 html 页面。

如果您到浏览器中的页面并单击右键 ==> 然后按检查 ==> 然后 go 到网络 ==> 然后选择请求的页面 ==> 然后选择响应,您可以找到所需的带有更新数据的页面

to make it visible on the screen you need to go to java script file of the front end and put an call back function with response which is the html page such like so

.then(res => {
     document.open()
     res.text().then(function(text) {

           document.write(text)
          });

          })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM