Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript变量作为EJS数组的索引-NODEJS_Javascript_Jquery_Node.js_Ejs - Fatal编程技术网

使用Javascript变量作为EJS数组的索引-NODEJS

使用Javascript变量作为EJS数组的索引-NODEJS,javascript,jquery,node.js,ejs,Javascript,Jquery,Node.js,Ejs,这是我的Jquery代码 $(document).on("click", "a.icons", function() { var eventId = $(this).data('id'); var patientName = "<%= patients_list["+eventId+"].full_name%>"; $('#idHolder').html(pati

这是我的Jquery代码

$(document).on("click", "a.icons", function() {
                    var eventId = $(this).data('id');
                    var patientName =  "<%= patients_list["+eventId+"].full_name%>";
                    $('#idHolder').html(patientName);

                });
$(文档)。在(“单击”,“a.icons”,函数()上){
var eventId=$(this.data('id');
var patientName=“”;
$('#idHolder').html(patientName);
});
我想要的是使用Javascript变量作为EJS数组的索引


非常感谢您的帮助。

您可以将EJS阵列转换为JS阵列:

// Create a JS variable and assign your EJS variable value
var patients_list = <%- JSON.stringify(patients_list) %>;
$(document).on("click", "a.icons", function() {
  var eventId = $(this).data('id');
  var patientName =  patients_list[eventId].full_name;
  $('#idHolder').html(patientName);
});
//创建一个JS变量并分配您的EJS变量值
var患者_列表=;
$(文档)。在(“单击”,“a.icons”,函数()上){
var eventId=$(this.data('id');
var patientName=患者列表[eventId]。全名;
$('#idHolder').html(patientName);
});

您可以将EJS阵列转换为JS阵列:

// Create a JS variable and assign your EJS variable value
var patients_list = <%- JSON.stringify(patients_list) %>;
$(document).on("click", "a.icons", function() {
  var eventId = $(this).data('id');
  var patientName =  patients_list[eventId].full_name;
  $('#idHolder').html(patientName);
});
//创建一个JS变量并分配您的EJS变量值
var患者_列表=;
$(文档)。在(“单击”,“a.icons”,函数()上){
var eventId=$(this.data('id');
var patientName=患者列表[eventId]。全名;
$('#idHolder').html(patientName);
});

你试过吗?是的,我试过@MrJIt shows全名没有定义你怎么能想象我们能用这么少的代码来回答你!你试过了吗?是的,我试过了@MrJIt shows全名没有定义你怎么能想象我们能用这么少的代码来回答你!