尝试使用一些嵌入式Javascript将从我们的SQL Server获取的数据传递到EJS模板。以下是一些代码片段,向您展示了我正在尝试做的事情。
路由文件
const data = await sqlCalls.getMenuAccess(req.user.UserIdNo)
const data2 = await sqlCalls.getAvailability();
const menus = data.recordset
const availability = data2.recordset
res.render('portal-availability',
{
title: 'Availability',
name: req.user.FirstName,
menudata: menus,
availabilitydata: availability // <--- This is the data that I want to use in my EJS template.
});
});
我的EJS模板的HTML部分
<section class="content">
<div class="container-fluid">
<div class="block-header">
<h2>AVAILABILITY</h2>
</div>
<div id="grid"></div>
</div>
</section>
我的EJS模板中的Javascript
<script>
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
data: availability, // <---- This is where I am trying to use availability to bind to my grid.
schema: {
model: {
fields: {
ItemIdNo: { type: "number" },
cultivardescription: { type: "string" },
containerdescription: { type: "string" },
week0: { type: "number" }
}
}
}
});
});
</script>
任何帮助将不胜感激。
谢谢! 吉姆