简体   繁体   English

如何访问index.ejs的javascript部分中的本地数据(视图)?

[英]How to access locals data in javascript part of index.ejs (view)?

I am using Express.js and sending a get request and trying to use the response in the javascript part of the view (EJS template) 我正在使用Express.js并发送get请求,并尝试在视图的JavaScript部分(EJS模板)中使用响应

 <% if(locals.results) { %>

 <% results.forEach(function( result ) { %>

but I can't use this within script tag to access the results. 但是我不能在script标签内使用它来访问结果。

(This is working to print results in html tags but I want to pass it to a javascript function) (这可以在html标签中打印结果,但我想将其传递给javascript函数)

通过将响应文本添加到隐藏的段落元素并在javascript中阅读来解决问题

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

相关问题 我应该如何使用 webpack DefinePlugin 访问 index.ejs 中的哈希包文件名 - How should I access hash bundle file name in index.ejs using webpack DefinePlugin 如何通过app.js将另一个.js文件中所需的功能传递到index.ejs视图中 - How to pass function required from another .js file into an index.ejs view via app.js 如何将数据从一个 app.js 文件发送到 Routes 中的 index.ejs 文件 - how do I send data from one app.js file to index.ejs file in Routes 无法在视图目录中查找视图“index.ejs” - Failed to lookup view "index.ejs" in views directory 如果输入字段为空,如何渲染到 index.ejs? - How to render to index.ejs if input field is empty? 在index.ejs中显示multer(音乐)文件 - Displaying multer (music) files in index.ejs index.ejs中的Angular Controller错误 - Angular Controller error in index.ejs 将数据从 data.json 文件解析为 index.ejs (expressJS) - Parse data into index.ejs from data.json file (expressJS) (node/express) 从数据库查询中收集多条数据并发送到 index.ejs? - (node/express) Collecting multiple pieces of data from database queries and sending to index.ejs? 语法错误:编译 ejs 时 index.ejs 中出现意外标识符 - SyntaxError: Unexpected identifier in index.ejs while compiling ejs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM