Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
102 views
in Technique[技术] by (71.8m points)

node.js - Make request with ejs

I am making a nodejs app and have a particular view where a partial is needed.

I have this partial

<div class="form-group">
    <label for="start">Αφετηρ?α</label>
    <select class="form-control" id="start">
      <%= stations.foreach((station) => {%>
        <option><%= station %> </option>
        <%=}) %> 
    </select>
  </div>

That i feed stations through this

router.get('/stations', scheduleController.stations_list)

//and in the controller

const stations_list = (req, res) => {
    Station.find({}, {name: 1, _id: 0}).sort({name: 1})
    .then((result) => {
        res.render('/views/partials/stationList.ejs', {stations: result})
    })
}

now if i were to simply include this partial it would not get data. I would need to go through the controller for it.

I can think of 2 ways right now.

  1. Make the partial a part of the central view and feed it normally. it would work on this case but on others i would have to go with 2

  2. Use javascript to get the data and create an element through it populated by the json the server gives through a request.

But i would like to know if there is a way to make a request through the ejs tag since it would be the cleanest way

question from:https://stackoverflow.com/questions/65598884/make-request-with-ejs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...