简体   繁体   English

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

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

I have two selects in my view and I need to populate each one with a different array.我的视图中有两个选择,我需要用不同的数组填充每个选择。 How do I pass two different jons using res.render?如何使用 res.render 传递两个不同的 jons? I tried the way below, but it didn't work.我尝试了下面的方法,但没有奏效。

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

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

That way, the page is processing and never updates.这样,页面正在处理并且永远不会更新。 If anyone can help me thank you.如果有人可以帮助我,谢谢。

if there is no errors, this page will successfully send to the browser but it won't rendered because the browser expect to receive an json content not an html page.如果没有错误,此页面将成功发送到浏览器,但不会呈现,因为浏览器希望接收 json 内容而不是 html 页面。

you can find the required page with the updated data if you to the page in the browser and clicked right click ==> then press inspect ==> then go to Network ==> then choose the requested page ==> then choose response如果您到浏览器中的页面并单击右键 ==> 然后按检查 ==> 然后 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 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